mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 17:27:51 -06:00
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:
parent
f849df6ba3
commit
d52be42e01
1 changed files with 12 additions and 5 deletions
|
@ -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
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -26,7 +29,8 @@ def test_login():
|
||||||
mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False)
|
mocked_auth_service.startAuthorizationFlow.assert_called_once_with(False)
|
||||||
|
|
||||||
# Fake a successful login
|
# 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.
|
# Attempting to log in again shouldn't change anything.
|
||||||
account.login()
|
account.login()
|
||||||
|
@ -59,7 +63,8 @@ def test_logout():
|
||||||
assert not account.isLoggedIn
|
assert not account.isLoggedIn
|
||||||
|
|
||||||
# Pretend the stage changed
|
# 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
|
assert account.isLoggedIn
|
||||||
|
|
||||||
account.logout()
|
account.logout()
|
||||||
|
@ -72,12 +77,14 @@ def test_errorLoginState(application):
|
||||||
account._authorization_service = mocked_auth_service
|
account._authorization_service = mocked_auth_service
|
||||||
account.loginStateChanged = MagicMock()
|
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.
|
# Even though we said that the login worked, it had an error message, so the login failed.
|
||||||
account.loginStateChanged.emit.called_with(False)
|
account.loginStateChanged.emit.called_with(False)
|
||||||
|
|
||||||
account._onLoginStateChanged(True)
|
with patch("UM.TaskManagement.HttpRequestManager.HttpRequestManager.getInstance"):
|
||||||
account._onLoginStateChanged(False, "OMGZOMG!")
|
account._onLoginStateChanged(True)
|
||||||
|
account._onLoginStateChanged(False, "OMGZOMG!")
|
||||||
account.loginStateChanged.emit.called_with(False)
|
account.loginStateChanged.emit.called_with(False)
|
||||||
|
|
||||||
def test_sync_success():
|
def test_sync_success():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue