Skip to content

Commit

Permalink
type checking fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Oct 17, 2024
1 parent 79cdff9 commit 3dd8838
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/blueapi/service/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def print_user_info(self, token: str) -> None:

class TokenManager(ABC):
@abstractmethod
def save_token(self, token: dict[str, Any]): ...
def save_token(self, token: dict[str, Any]) -> None: ...
@abstractmethod
def load_token(token) -> dict[str, Any] | None: ...
@abstractmethod
Expand Down Expand Up @@ -119,6 +119,7 @@ def from_config(
client_config,
CLITokenManager(Path(client_config.token_file_path)),
)
return None

def get_token(self) -> dict[str, Any] | None:
return self._token_manager.load_token()
Expand All @@ -139,19 +140,21 @@ def refresh_auth_token(self) -> dict[str, Any] | None:
)
if response.status_code == HTTPStatus.OK:
token = response.json()
self._token_manager.save_token(token)
return token
if token:
self._token_manager.save_token(token)
return token
return None

def get_device_code(self):
response: requests.Response = requests.post(
response = requests.post(
self._server_config.token_url,
data={
"client_id": self._client_config.client_id,
"scope": "openid profile offline_access",
"audience": self._client_config.client_audience,
},
)
response_data: dict[str, str] = response.json()
response_data = response.json()
if response.status_code == 200:
return response_data["device_code"]
raise Exception("Failed to get device code.")

Check warning on line 160 in src/blueapi/service/authentication.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/service/authentication.py#L160

Added line #L160 was not covered by tests
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/service/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def mock_server_config(mock_requests_get) -> OAuthServerConfig:


@pytest.fixture
def mock_session_manager(mock_client_config, mock_server_config) -> SessionManager:
session_manager = SessionManager.from_config(mock_server_config, mock_client_config)
return session_manager
def mock_session_manager(
mock_client_config: OAuthClientConfig, mock_server_config: OAuthServerConfig
) -> SessionManager | None:
return SessionManager.from_config(mock_server_config, mock_client_config)


@pytest.fixture
Expand Down

0 comments on commit 3dd8838

Please sign in to comment.