mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Fix refactor and tests
This commit is contained in:
parent
6e46772170
commit
3a01b63343
3 changed files with 17 additions and 10 deletions
|
@ -23,7 +23,7 @@ class BackupsManager:
|
|||
# containing some metadata (like version).
|
||||
def createBackup(self) -> Tuple[Optional[bytes], Optional[Dict[str, str]]]:
|
||||
self._disableAutoSave()
|
||||
backup = Backup()
|
||||
backup = Backup(self._application)
|
||||
backup.makeFromCurrent()
|
||||
self._enableAutoSave()
|
||||
# We don't return a Backup here because we want plugins only to interact with our API and not full objects.
|
||||
|
|
|
@ -39,6 +39,7 @@ class AuthorizationService:
|
|||
self._server = LocalAuthorizationServer(self._auth_helpers, self._onAuthStateChanged, daemon=True)
|
||||
|
||||
def initialize(self, preferences: Optional["Preferences"] = None) -> None:
|
||||
if preferences is not None:
|
||||
self._preferences = preferences
|
||||
if self._preferences:
|
||||
self._preferences.addPreference(self._settings.AUTH_DATA_PREFERENCE_KEY, "{}")
|
||||
|
|
|
@ -31,15 +31,17 @@ MALFORMED_AUTH_RESPONSE = AuthenticationResponse()
|
|||
|
||||
def test_cleanAuthService() -> None:
|
||||
# Ensure that when setting up an AuthorizationService, no data is set.
|
||||
authorization_service = AuthorizationService(Preferences(), OAUTH_SETTINGS)
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||
authorization_service.initialize()
|
||||
assert authorization_service.getUserProfile() is None
|
||||
assert authorization_service.getAccessToken() is None
|
||||
|
||||
|
||||
def test_failedLogin() -> None:
|
||||
authorization_service = AuthorizationService(Preferences(), OAUTH_SETTINGS)
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||
authorization_service.onAuthenticationError.emit = MagicMock()
|
||||
authorization_service.onAuthStateChanged.emit = MagicMock()
|
||||
authorization_service.initialize()
|
||||
|
||||
# Let the service think there was a failed response
|
||||
authorization_service._onAuthStateChanged(FAILED_AUTH_RESPONSE)
|
||||
|
@ -58,7 +60,8 @@ def test_failedLogin() -> None:
|
|||
@patch.object(AuthorizationService, "getUserProfile", return_value=UserProfile())
|
||||
def test_storeAuthData(get_user_profile) -> None:
|
||||
preferences = Preferences()
|
||||
authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences)
|
||||
authorization_service.initialize()
|
||||
|
||||
# Write stuff to the preferences.
|
||||
authorization_service._storeAuthData(SUCCESFULL_AUTH_RESPONSE)
|
||||
|
@ -67,7 +70,8 @@ def test_storeAuthData(get_user_profile) -> None:
|
|||
assert preference_value is not None and preference_value != {}
|
||||
|
||||
# Create a second auth service, so we can load the data.
|
||||
second_auth_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
||||
second_auth_service = AuthorizationService(OAUTH_SETTINGS, preferences)
|
||||
second_auth_service.initialize()
|
||||
second_auth_service.loadAuthDataFromPreferences()
|
||||
assert second_auth_service.getAccessToken() == SUCCESFULL_AUTH_RESPONSE.access_token
|
||||
|
||||
|
@ -77,7 +81,7 @@ def test_storeAuthData(get_user_profile) -> None:
|
|||
@patch.object(webbrowser, "open_new")
|
||||
def test_localAuthServer(webbrowser_open, start_auth_server, stop_auth_server) -> None:
|
||||
preferences = Preferences()
|
||||
authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences)
|
||||
authorization_service.startAuthorizationFlow()
|
||||
assert webbrowser_open.call_count == 1
|
||||
|
||||
|
@ -92,9 +96,10 @@ def test_localAuthServer(webbrowser_open, start_auth_server, stop_auth_server) -
|
|||
|
||||
def test_loginAndLogout() -> None:
|
||||
preferences = Preferences()
|
||||
authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences)
|
||||
authorization_service.onAuthenticationError.emit = MagicMock()
|
||||
authorization_service.onAuthStateChanged.emit = MagicMock()
|
||||
authorization_service.initialize()
|
||||
|
||||
# Let the service think there was a succesfull response
|
||||
with patch.object(AuthorizationHelpers, "parseJWT", return_value=UserProfile()):
|
||||
|
@ -121,7 +126,8 @@ def test_loginAndLogout() -> None:
|
|||
|
||||
|
||||
def test_wrongServerResponses() -> None:
|
||||
authorization_service = AuthorizationService(Preferences(), OAUTH_SETTINGS)
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||
authorization_service.initialize()
|
||||
with patch.object(AuthorizationHelpers, "parseJWT", return_value=UserProfile()):
|
||||
authorization_service._onAuthStateChanged(MALFORMED_AUTH_RESPONSE)
|
||||
assert authorization_service.getUserProfile() is None
|
Loading…
Add table
Add a link
Reference in a new issue