mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Typing fixes
CURA-5744
This commit is contained in:
parent
f16a9c62b5
commit
b48adf5b3e
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user