Add tests for loginWithForcedLogout() in account

CURA-7427
This commit is contained in:
Kostas Karmas 2020-05-12 13:06:47 +02:00
parent e3e767f4b9
commit 96387ef2aa
2 changed files with 22 additions and 2 deletions

View File

@ -99,7 +99,7 @@ class Account(QObject):
@pyqtSlot() @pyqtSlot()
def loginWithForcedLogout(self) -> None: 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. as true, to sync the accounts in Cura and in the browser.
:return: None :return: None

View File

@ -23,7 +23,7 @@ def test_login():
account.login() account.login()
mocked_auth_service.startAuthorizationFlow.assert_called_once_with() mocked_auth_service.startAuthorizationFlow.assert_called_once_with()
# Fake a sucesfull login # Fake a successful login
account._onLoginStateChanged(True) account._onLoginStateChanged(True)
# Attempting to log in again shouldn't change anything. # Attempting to log in again shouldn't change anything.
@ -31,6 +31,26 @@ def test_login():
mocked_auth_service.startAuthorizationFlow.assert_called_once_with() 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(): def test_initialize():
account = Account(MagicMock()) account = Account(MagicMock())
mocked_auth_service = MagicMock() mocked_auth_service = MagicMock()