Skip to content

Commit 04e7e36

Browse files
committed
fix: linting issue in start_local_http_server.py
1 parent a6d9c09 commit 04e7e36

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

eventsourcingdb_client_python/handlers/ping.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
OK_RESPONSE = "OK"
88
STATUS_OK = "ok"
99

10+
# CloudEvent field names
11+
SPECVERSION_FIELD = "specversion"
12+
TYPE_FIELD = "type"
13+
PING_RECEIVED_TYPE = "io.eventsourcingdb.ping-received"
14+
1015

1116
async def ping(client: AbstractBaseClient) -> None:
1217
response = await client.http_client.get("/api/v1/ping")
@@ -21,8 +26,8 @@ async def ping(client: AbstractBaseClient) -> None:
2126

2227
try:
2328
response_json = json.loads(response_body)
24-
except json.JSONDecodeError:
25-
raise ServerError(f"Received unexpected response: {response_body}")
29+
except json.JSONDecodeError as exc:
30+
raise ServerError(f"Received unexpected response: {response_body}") from exc
2631

2732
# Check if it's a JSON with status field
2833
if isinstance(response_json, dict) and response_json.get("status") == STATUS_OK:
@@ -31,10 +36,10 @@ async def ping(client: AbstractBaseClient) -> None:
3136
# Check if it's a CloudEvent format (has specversion, type fields)
3237
if (
3338
isinstance(response_json, dict)
34-
and "specversion" in response_json
35-
and "type" in response_json
39+
and SPECVERSION_FIELD in response_json
40+
and TYPE_FIELD in response_json
3641
):
37-
if response_json.get("type") == "io.eventsourcingdb.ping-received":
42+
if response_json.get(TYPE_FIELD) == PING_RECEIVED_TYPE:
3843
return
3944

4045
raise ServerError(f"Received unexpected response: {response_body}")

tests/shared/start_local_http_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ async def ping_app() -> RetryResult[None]:
4848
async with session:
4949
try:
5050
response = await session.get(
51-
f'http://localhost:{local_http_server.port}/__python_test__/api/v1/ping', timeout=aiohttp.ClientTimeout(total=1) # noqa: E501
52-
)
51+
f'http://localhost:{local_http_server.port}/__python_test__/api/v1/ping',
52+
timeout=aiohttp.ClientTimeout(total=1))
5353
except aiohttp.ClientError as error:
5454
return Retry(cause=error)
5555
if not response.ok:

0 commit comments

Comments
 (0)