Fix OAuth2 test

This commit is contained in:
Lipu Fei 2019-08-15 09:23:05 +02:00
parent 4c792419e3
commit e8fd013329

View file

@ -1,9 +1,10 @@
import webbrowser
from datetime import datetime from datetime import datetime
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import requests import requests
from PyQt5.QtGui import QDesktopServices
from UM.Preferences import Preferences from UM.Preferences import Preferences
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT
from cura.OAuth2.AuthorizationService import AuthorizationService from cura.OAuth2.AuthorizationService import AuthorizationService
@ -172,12 +173,12 @@ def test_storeAuthData(get_user_profile) -> None:
@patch.object(LocalAuthorizationServer, "stop") @patch.object(LocalAuthorizationServer, "stop")
@patch.object(LocalAuthorizationServer, "start") @patch.object(LocalAuthorizationServer, "start")
@patch.object(webbrowser, "open_new") @patch.object(QDesktopServices, "openUrl")
def test_localAuthServer(webbrowser_open, start_auth_server, stop_auth_server) -> None: def test_localAuthServer(QDesktopServices_openUrl, start_auth_server, stop_auth_server) -> None:
preferences = Preferences() preferences = Preferences()
authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences) authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences)
authorization_service.startAuthorizationFlow() authorization_service.startAuthorizationFlow()
assert webbrowser_open.call_count == 1 assert QDesktopServices_openUrl.call_count == 1
# Ensure that the Authorization service tried to start the server. # Ensure that the Authorization service tried to start the server.
assert start_auth_server.call_count == 1 assert start_auth_server.call_count == 1