mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 09:59:00 +08:00
Add LocalAuthServer test
This is to ensure that once we try to login, it actually attempts to start the local server CURA-5744
This commit is contained in:
parent
fe85c020b1
commit
7360313ff7
@ -1,8 +1,10 @@
|
|||||||
|
import webbrowser
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from UM.Preferences import Preferences
|
from UM.Preferences import Preferences
|
||||||
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers
|
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers
|
||||||
from cura.OAuth2.AuthorizationService import AuthorizationService
|
from cura.OAuth2.AuthorizationService import AuthorizationService
|
||||||
|
from cura.OAuth2.LocalAuthorizationServer import LocalAuthorizationServer
|
||||||
from cura.OAuth2.Models import OAuth2Settings, AuthenticationResponse, UserProfile
|
from cura.OAuth2.Models import OAuth2Settings, AuthenticationResponse, UserProfile
|
||||||
|
|
||||||
CALLBACK_PORT = 32118
|
CALLBACK_PORT = 32118
|
||||||
@ -53,6 +55,24 @@ def test_failedLogin():
|
|||||||
assert authorization_service.getAccessToken() is None
|
assert authorization_service.getAccessToken() is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_localAuthServer():
|
||||||
|
preferences = Preferences()
|
||||||
|
authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
||||||
|
with patch.object(webbrowser, "open_new") as webrowser_open:
|
||||||
|
with patch.object(LocalAuthorizationServer, "start") as start_auth_server:
|
||||||
|
with patch.object(LocalAuthorizationServer, "stop") as stop_auth_server:
|
||||||
|
authorization_service.startAuthorizationFlow()
|
||||||
|
assert webrowser_open.call_count == 1
|
||||||
|
|
||||||
|
# Ensure that the Authorization service tried to start the server.
|
||||||
|
assert start_auth_server.call_count == 1
|
||||||
|
assert stop_auth_server.call_count == 0
|
||||||
|
authorization_service._onAuthStateChanged(FAILED_AUTH_RESPONSE)
|
||||||
|
|
||||||
|
# Ensure that it stopped the server.
|
||||||
|
assert stop_auth_server.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_loginAndLogout():
|
def test_loginAndLogout():
|
||||||
preferences = Preferences()
|
preferences = Preferences()
|
||||||
authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user