From b48adf5b3e4fd68f3329105d17a668021738df9f Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 24 Sep 2018 17:37:06 +0200 Subject: [PATCH] Typing fixes CURA-5744 --- cura/API/Account.py | 4 ++-- cura/OAuth2/AuthorizationRequestHandler.py | 6 +++--- cura/OAuth2/LocalAuthorizationServer.py | 3 +-- tests/TestOAuth2.py | 10 +++++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index cb80131425..6bb5b4e50d 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -1,6 +1,6 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from typing import Tuple, Optional, Dict +from typing import Optional, Dict from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, pyqtProperty @@ -48,7 +48,7 @@ class Account(QObject): self._authorization_service.onAuthStateChanged.connect(self._onLoginStateChanged) self._authorization_service.onAuthenticationError.connect(self._onLoginStateChanged) - self._error_message = None + self._error_message = None # type: Optional[Message] self._logged_in = False @pyqtProperty(bool, notify=loginStateChanged) diff --git a/cura/OAuth2/AuthorizationRequestHandler.py b/cura/OAuth2/AuthorizationRequestHandler.py index 0558db784f..3b5b0c34d8 100644 --- a/cura/OAuth2/AuthorizationRequestHandler.py +++ b/cura/OAuth2/AuthorizationRequestHandler.py @@ -5,11 +5,11 @@ from typing import Optional, Callable, Tuple, Dict, Any, List, TYPE_CHECKING from http.server import BaseHTTPRequestHandler from urllib.parse import parse_qs, urlparse -from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers from cura.OAuth2.Models import AuthenticationResponse, ResponseData, HTTP_STATUS if TYPE_CHECKING: from cura.OAuth2.Models import ResponseStatus + from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers class AuthorizationRequestHandler(BaseHTTPRequestHandler): @@ -22,7 +22,7 @@ class AuthorizationRequestHandler(BaseHTTPRequestHandler): super().__init__(request, client_address, server) # These values will be injected by the HTTPServer that this handler belongs to. - self.authorization_helpers = None # type: Optional[AuthorizationHelpers] + self.authorization_helpers = None # type: Optional["AuthorizationHelpers"] self.authorization_callback = None # type: Optional[Callable[[AuthenticationResponse], None]] self.verification_code = None # type: Optional[str] @@ -52,7 +52,7 @@ class AuthorizationRequestHandler(BaseHTTPRequestHandler): # This will cause the server to shut down, so we do it at the very end of the request handling. self.authorization_callback(token_response) - def _handleCallback(self, query: Dict[Any, List]) -> Tuple["ResponseData", Optional["AuthenticationResponse"]]: + def _handleCallback(self, query: Dict[Any, List]) -> Tuple[ResponseData, Optional[AuthenticationResponse]]: """ Handler for the callback URL redirect. :param query: Dict containing the HTTP query parameters. diff --git a/cura/OAuth2/LocalAuthorizationServer.py b/cura/OAuth2/LocalAuthorizationServer.py index d1d07b5c91..488a33941d 100644 --- a/cura/OAuth2/LocalAuthorizationServer.py +++ b/cura/OAuth2/LocalAuthorizationServer.py @@ -5,13 +5,12 @@ from typing import Optional, Callable, Any, TYPE_CHECKING from UM.Logger import Logger -from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers from cura.OAuth2.AuthorizationRequestServer import AuthorizationRequestServer from cura.OAuth2.AuthorizationRequestHandler import AuthorizationRequestHandler if TYPE_CHECKING: from cura.OAuth2.Models import AuthenticationResponse - + from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers class LocalAuthorizationServer: def __init__(self, auth_helpers: "AuthorizationHelpers", diff --git a/tests/TestOAuth2.py b/tests/TestOAuth2.py index 708dd2d41b..7deb712aea 100644 --- a/tests/TestOAuth2.py +++ b/tests/TestOAuth2.py @@ -29,14 +29,14 @@ SUCCESFULL_AUTH_RESPONSE = AuthenticationResponse(access_token = "beep", refresh MALFORMED_AUTH_RESPONSE = AuthenticationResponse() -def test_cleanAuthService(): +def test_cleanAuthService() -> None: # Ensure that when setting up an AuthorizationService, no data is set. authorization_service = AuthorizationService(Preferences(), OAUTH_SETTINGS) assert authorization_service.getUserProfile() is None assert authorization_service.getAccessToken() is None -def test_failedLogin(): +def test_failedLogin() -> None: authorization_service = AuthorizationService(Preferences(), OAUTH_SETTINGS) authorization_service.onAuthenticationError.emit = MagicMock() authorization_service.onAuthStateChanged.emit = MagicMock() @@ -55,7 +55,7 @@ def test_failedLogin(): assert authorization_service.getAccessToken() is None -def test_localAuthServer(): +def test_localAuthServer() -> None: preferences = Preferences() authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS) with patch.object(webbrowser, "open_new") as webrowser_open: @@ -73,7 +73,7 @@ def test_localAuthServer(): assert stop_auth_server.call_count == 1 -def test_loginAndLogout(): +def test_loginAndLogout() -> None: preferences = Preferences() authorization_service = AuthorizationService(preferences, OAUTH_SETTINGS) authorization_service.onAuthenticationError.emit = MagicMock() @@ -103,7 +103,7 @@ def test_loginAndLogout(): assert preferences.getValue("test/auth_data") == "{}" -def test_wrongServerResponses(): +def test_wrongServerResponses() -> None: authorization_service = AuthorizationService(Preferences(), OAUTH_SETTINGS) with patch.object(AuthorizationHelpers, "parseJWT", return_value=UserProfile()): authorization_service._onAuthStateChanged(MALFORMED_AUTH_RESPONSE)