Skip to content

Commit a2f794d

Browse files
author
Virag Sharma
committed
fix: fix for the failing signature status
1 parent c4871e7 commit a2f794d

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/grz-db/src/grz_db/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def serialize_datetime_to_iso_z(dt: datetime.datetime) -> str:
5858
if dt.tzinfo != datetime.UTC and dt.utcoffset() != datetime.timedelta(0):
5959
dt = dt.astimezone(datetime.UTC)
6060

61-
return dt.isoformat()
61+
return dt.isoformat().replace("+00:00", "Z")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import datetime
2+
3+
import pytest
4+
from grz_db.common import serialize_datetime_to_iso_z
5+
6+
7+
@pytest.mark.parametrize(
8+
"dt,description",
9+
[
10+
# SQLite: reads back as naive (no tzinfo)
11+
(datetime.datetime(2024, 1, 1, 12, 0, 0), "SQLite naive datetime"),
12+
# PostgreSQL: reads back as timezone-aware UTC
13+
(datetime.datetime(2024, 1, 1, 12, 0, 0, tzinfo=datetime.UTC), "PostgreSQL UTC datetime"),
14+
# Non-UTC timezone (should be converted to UTC)
15+
(
16+
datetime.datetime(2024, 1, 1, 13, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=1))),
17+
"Non-UTC timezone",
18+
),
19+
],
20+
)
21+
def test_serialize_datetime_to_iso_z_database_agnostic(dt, description):
22+
"""
23+
serialize_datetime_to_iso_z must produce identical 'Z'-suffixed output
24+
regardless of whether the datetime came from SQLite (naive) or PostgreSQL (timezone-aware).
25+
This ensures signature verification works consistently across database backends.
26+
"""
27+
result = serialize_datetime_to_iso_z(dt)
28+
assert result.endswith("Z"), f"{description}: Expected 'Z' suffix, got: {result}"
29+
assert "+00:00" not in result, f"{description}: Should not contain '+00:00'"
30+
# All should normalize to the same UTC representation
31+
assert result == "2024-01-01T12:00:00Z", f"{description}: Expected normalized UTC, got: {result}"

0 commit comments

Comments
 (0)