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.
This commit is contained in:
Ghostkeeper 2022-07-27 10:49:30 +02:00
parent f849df6ba3
commit d52be42e01
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -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,6 +29,7 @@ def test_login():
mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False)
# Fake a successful login
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.
@ -59,6 +63,7 @@ def test_logout():
assert not account.isLoggedIn
# Pretend the stage changed
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
@ -72,10 +77,12 @@ def test_errorLoginState(application):
account._authorization_service = mocked_auth_service
account.loginStateChanged = MagicMock()
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)
with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance"):
account._onLoginStateChanged(True)
account._onLoginStateChanged(False, "OMGZOMG!")
account.loginStateChanged.emit.called_with(False)