Skip to content

Commit 4b5ab57

Browse files
CopilotiMicknl
andcommitted
Improve code based on review feedback: use _create_local_ssl_context directly and clarify mypy comment
Co-authored-by: iMicknl <1424596+iMicknl@users.noreply.github.com>
1 parent bfac34b commit 4b5ab57

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

pyoverkiz/client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,8 @@ def __init__(
166166
if self.server_config.type == APIType.LOCAL and verify_ssl:
167167
# To avoid security issues while authentication to local API, we add the following authority to
168168
# our HTTPS client trust store: https://ca.overkiz.com/overkiz-root-ca-2048.crt
169-
# Create a copy of the SSL context to avoid mutating the shared global context
170-
self._ssl = ssl.SSLContext(SSL_CONTEXT_LOCAL_API.protocol)
171-
self._ssl.load_verify_locations(
172-
cafile=os.path.dirname(os.path.realpath(__file__))
173-
+ "/overkiz-root-ca-2048.crt"
174-
)
169+
# Create a new SSL context to avoid mutating the shared global context
170+
self._ssl = _create_local_ssl_context()
175171

176172
# Disable strict validation introduced in Python 3.13, which doesn't
177173
# work with Overkiz self-signed gateway certificates

pyoverkiz/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def create_server_config(
3737
configuration_url: str | None = None,
3838
) -> ServerConfig:
3939
"""Generate server configuration with the provided endpoint and metadata."""
40-
# ServerConfig.__init__ handles the enum conversion, but mypy doesn't see it
41-
# due to attrs @define decorator, so we need type: ignore comments.
40+
# ServerConfig.__init__ handles the enum conversion, but mypy doesn't recognize
41+
# this due to attrs @define decorator generating __init__ with stricter signatures,
42+
# so we need type: ignore comments.
4243
return ServerConfig(
4344
server=server, # type: ignore[arg-type]
4445
name=name,

tests/test_auth.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from __future__ import annotations
44

55
import datetime
6-
import ssl
7-
from unittest.mock import AsyncMock, MagicMock, Mock, patch
6+
from unittest.mock import AsyncMock, MagicMock
87

98
import pytest
109
from aiohttp import ClientSession
@@ -108,9 +107,7 @@ def test_ensure_username_password_valid(self):
108107
def test_ensure_username_password_invalid(self):
109108
"""Test that invalid credentials raise TypeError."""
110109
creds = TokenCredentials("token")
111-
with pytest.raises(
112-
TypeError, match="UsernamePasswordCredentials are required"
113-
):
110+
with pytest.raises(TypeError, match="UsernamePasswordCredentials are required"):
114111
_ensure_username_password(creds)
115112

116113
def test_ensure_token_valid(self):
@@ -332,9 +329,7 @@ async def test_build_auth_strategy_wrong_credentials_type(self):
332329
credentials = TokenCredentials("token") # Wrong type for Somfy
333330
session = AsyncMock(spec=ClientSession)
334331

335-
with pytest.raises(
336-
TypeError, match="UsernamePasswordCredentials are required"
337-
):
332+
with pytest.raises(TypeError, match="UsernamePasswordCredentials are required"):
338333
build_auth_strategy(
339334
server_config=server_config,
340335
credentials=credentials,

0 commit comments

Comments
 (0)