Skip to content

Commit 19dbcf7

Browse files
tmdeveloper007utksh1
authored andcommitted
test: add unit tests for _now_iso helper in platform_resources
1 parent 837bdce commit 19dbcf7

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

testing/backend/unit/test_platform_resources.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Unit tests for backend/secuscan/platform_resources.py
33
44
Covers the pure helpers exposed by the module:
5+
- _now_iso: UTC timestamp in ISO 8601 format
56
- _stable_asset_id: deterministic asset id derivation
67
- _deserialize_resource_row: unwrap *_json columns
78
- deserialize_resource_rows: filter None rows
@@ -20,6 +21,7 @@
2021
from backend.secuscan.execution_context import normalize_execution_context
2122
from backend.secuscan.platform_resources import (
2223
_deserialize_resource_row,
24+
_now_iso,
2325
_stable_asset_id,
2426
deserialize_resource_rows,
2527
serialize_execution_context,
@@ -213,3 +215,36 @@ def test_empty_context_produces_full_default_payload(self):
213215
# The default ExecutionContext has at least these two fields
214216
assert "validation_mode" in parsed
215217
assert "evidence_level" in parsed
218+
219+
220+
# ---------------------------------------------------------------------------
221+
# _now_iso
222+
223+
class TestNowIso:
224+
def test_returns_string(self):
225+
"""_now_iso returns a string."""
226+
result = _now_iso()
227+
assert isinstance(result, str)
228+
229+
def test_returns_iso_8601_format(self):
230+
"""_now_iso returns a valid ISO 8601 formatted datetime string."""
231+
result = _now_iso()
232+
# datetime.utcnow().isoformat() produces YYYY-MM-DDTHH:MM:SS[.ffffff]
233+
# The format is always ISO 8601 (UTC naive), e.g. 2026-08-03T07:48:42.438246
234+
import datetime as dt
235+
# Should parse without error
236+
parsed = dt.datetime.fromisoformat(result)
237+
assert isinstance(parsed, dt.datetime)
238+
assert "T" in result # ISO separator
239+
# Should contain the current year
240+
assert str(dt.datetime.utcnow().year) in result
241+
242+
def test_returns_time_within_a_few_seconds(self):
243+
"""_now_iso returns a time within a few seconds of now."""
244+
import datetime as dt
245+
before = dt.datetime.utcnow()
246+
result = _now_iso()
247+
after = dt.datetime.utcnow()
248+
parsed = dt.datetime.fromisoformat(result)
249+
# Should be between before and after
250+
assert before <= parsed <= after or after <= parsed <= before

0 commit comments

Comments
 (0)