From 96387ef2aa4459ac3891f2830143ace064282c4e Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 12 May 2020 13:06:47 +0200 Subject: [PATCH] Add tests for loginWithForcedLogout() in account CURA-7427 --- cura/API/Account.py | 2 +- tests/API/TestAccount.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index acf507e23f..f87f613382 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -99,7 +99,7 @@ class Account(QObject): @pyqtSlot() def loginWithForcedLogout(self) -> None: """ - Forces a logout from Cura and then initiates the authorization flow with the force_logout_from_mycloud variable + Forces a logout from Cura and then initiates the authorization flow with the force_browser_logout variable as true, to sync the accounts in Cura and in the browser. :return: None diff --git a/tests/API/TestAccount.py b/tests/API/TestAccount.py index 4c6141e782..1b23947cc0 100644 --- a/tests/API/TestAccount.py +++ b/tests/API/TestAccount.py @@ -23,7 +23,7 @@ def test_login(): account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with() - # Fake a sucesfull login + # Fake a successful login account._onLoginStateChanged(True) # Attempting to log in again shouldn't change anything. @@ -31,6 +31,26 @@ def test_login(): mocked_auth_service.startAuthorizationFlow.assert_called_once_with() +def test_loginWithForcedLogout(): + account = Account(MagicMock()) + mocked_auth_service = MagicMock() + account._authorization_service = mocked_auth_service + account.logout = MagicMock() + + # Fake a successful login + account._onLoginStateChanged(True) + account.loginWithForcedLogout() + # Make sure logout is called once + account.logout.assert_called_once_with() + mocked_auth_service.startAuthorizationFlow.assert_called_once_with(True) + + account._onLoginStateChanged(False) + account.loginWithForcedLogout() + # If we are not logged in previously, logout shouldn't be called again + account.logout.assert_called_once_with() + assert mocked_auth_service.startAuthorizationFlow.call_count == 2 + + def test_initialize(): account = Account(MagicMock()) mocked_auth_service = MagicMock()