diff options
author | Ghostkeeper <rubend@tutanota.com> | 2022-07-27 11:49:30 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2022-07-27 12:41:50 +0300 |
commit | d52be42e01480710920f2fc53ea2025e0798aa94 (patch) | |
tree | b43284209b29a078a9be5fac773dadbb374de1a8 /tests/API | |
parent | f849df6ba3819149bc35c5523867e78cbe754846 (diff) |
Mock HttpRequestManager while changing log-in state
Changing the log-in state causes additional requests to be made to get information from the account. Previously this wasn't a problem because the information was only obtained from other classes such as the DigitalLibrary to get information on how many library projects the user can make. But now that there are triggers in the Account class itself, those triggers get triggered. It'd make additional requests to the account server. We don't want the tests to make such requests.
Contributes to issue CURA-9220.
Diffstat (limited to 'tests/API')
-rw-r--r-- | tests/API/TestAccount.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/API/TestAccount.py b/tests/API/TestAccount.py index 1ad73462c2..820e7dfbf5 100644 --- a/tests/API/TestAccount.py +++ b/tests/API/TestAccount.py @@ -1,3 +1,6 @@ +# Copyright (c) 2022 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + from unittest.mock import MagicMock, patch import pytest @@ -26,7 +29,8 @@ def test_login(): mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False) # Fake a successful login - account._onLoginStateChanged(True) + with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance"): # Don't want triggers for account information to actually make HTTP requests. + account._onLoginStateChanged(True) # Attempting to log in again shouldn't change anything. account.login() @@ -59,7 +63,8 @@ def test_logout(): assert not account.isLoggedIn # Pretend the stage changed - account._onLoginStateChanged(True) + with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance"): # Don't want triggers for account information to actually make HTTP requests. + account._onLoginStateChanged(True) assert account.isLoggedIn account.logout() @@ -72,12 +77,14 @@ def test_errorLoginState(application): account._authorization_service = mocked_auth_service account.loginStateChanged = MagicMock() - account._onLoginStateChanged(True, "BLARG!") + with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance"): # Don't want triggers for account information to actually make HTTP requests. + 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!") + with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance"): + account._onLoginStateChanged(True) + account._onLoginStateChanged(False, "OMGZOMG!") account.loginStateChanged.emit.called_with(False) def test_sync_success(): |