def test_login(): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with() # Fake a sucesfull login account._onLoginStateChanged(True) # Attempting to log in again shouldn't change anything. account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with()
def test_login(): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with() # Fake a sucesfull login account._onLoginStateChanged(True) # Attempting to log in again shouldn't change anything. account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with()
def test_logout(): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.logout() mocked_auth_service.deleteAuthData.assert_not_called() # We weren't logged in, so nothing should happen assert not account.isLoggedIn # Pretend the stage changed account._onLoginStateChanged(True) assert account.isLoggedIn account.logout() mocked_auth_service.deleteAuthData.assert_called_once_with()
def test_logout(): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.logout() mocked_auth_service.deleteAuthData.assert_not_called() # We weren't logged in, so nothing should happen assert not account.isLoggedIn # Pretend the stage changed account._onLoginStateChanged(True) assert account.isLoggedIn account.logout() mocked_auth_service.deleteAuthData.assert_called_once_with()
def test_login(): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.logout = MagicMock() account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False) # Fake a successful login account._onLoginStateChanged(True) # Attempting to log in again shouldn't change anything. account.login() mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False) # Attempting to log in with force_logout_before_login as True should call the logout before calling the # startAuthorizationFlow(True). account.login(force_logout_before_login=True) account.logout.assert_called_once_with() mocked_auth_service.startAuthorizationFlow.assert_called_with(True) assert mocked_auth_service.startAuthorizationFlow.call_count == 2
def test_errorLoginState(application): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.loginStateChanged = MagicMock() account._onLoginStateChanged(True, "BLARG!") # Even though we said that the login worked, it had an error message, so the login failed. account.loginStateChanged.emit.called_with(False) account._onLoginStateChanged(True) account._onLoginStateChanged(False, "OMGZOMG!") account.loginStateChanged.emit.called_with(False)
def test_errorLoginState(): account = Account(MagicMock()) mocked_auth_service = MagicMock() account._authorization_service = mocked_auth_service account.loginStateChanged = MagicMock() account._onLoginStateChanged(True, "BLARG!") # Even though we said that the login worked, it had an error message, so the login failed. account.loginStateChanged.emit.called_with(False) account._onLoginStateChanged(True) account._onLoginStateChanged(False, "OMGZOMG!") account.loginStateChanged.emit.called_with(False)