Merge pull request #7743 from Ultimaker/CURA-7427_Add_option_to_sign_in_with_different_account_while_waiting_for_printers

Cura 7427 add option to sign in with different account while waiting for printers
This commit is contained in:
Nino van Hooff 2020-05-12 17:39:07 +02:00 committed by GitHub
commit f34e05ac03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 18 deletions

View file

@ -19,16 +19,24 @@ 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()
mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False)
# Fake a sucesfull login
# 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()
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_initialize():

View file

@ -7,7 +7,7 @@ from PyQt5.QtGui import QDesktopServices
from UM.Preferences import Preferences
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT
from cura.OAuth2.AuthorizationService import AuthorizationService
from cura.OAuth2.AuthorizationService import AuthorizationService, MYCLOUD_LOGOFF_URL
from cura.OAuth2.LocalAuthorizationServer import LocalAuthorizationServer
from cura.OAuth2.Models import OAuth2Settings, AuthenticationResponse, UserProfile
@ -226,3 +226,19 @@ def test_wrongServerResponses() -> None:
with patch.object(AuthorizationHelpers, "parseJWT", return_value=UserProfile()):
authorization_service._onAuthStateChanged(MALFORMED_AUTH_RESPONSE)
assert authorization_service.getUserProfile() is None
def test__generate_auth_url() -> None:
preferences = Preferences()
authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences)
query_parameters_dict = {
"client_id": "",
"redirect_uri": OAUTH_SETTINGS.CALLBACK_URL,
"scope": OAUTH_SETTINGS.CLIENT_SCOPES,
"response_type": "code"
}
auth_url = authorization_service._generate_auth_url(query_parameters_dict, force_browser_logout = False)
assert MYCLOUD_LOGOFF_URL + "?next=" not in auth_url
auth_url = authorization_service._generate_auth_url(query_parameters_dict, force_browser_logout = True)
assert MYCLOUD_LOGOFF_URL + "?next=" in auth_url