|
2 | 2 | Unit tests for backend/secuscan/platform_resources.py |
3 | 3 |
|
4 | 4 | Covers the pure helpers exposed by the module: |
| 5 | + - _now_iso: UTC timestamp in ISO 8601 format |
5 | 6 | - _stable_asset_id: deterministic asset id derivation |
6 | 7 | - _deserialize_resource_row: unwrap *_json columns |
7 | 8 | - deserialize_resource_rows: filter None rows |
|
20 | 21 | from backend.secuscan.execution_context import normalize_execution_context |
21 | 22 | from backend.secuscan.platform_resources import ( |
22 | 23 | _deserialize_resource_row, |
| 24 | + _now_iso, |
23 | 25 | _stable_asset_id, |
24 | 26 | deserialize_resource_rows, |
25 | 27 | serialize_execution_context, |
@@ -213,3 +215,36 @@ def test_empty_context_produces_full_default_payload(self): |
213 | 215 | # The default ExecutionContext has at least these two fields |
214 | 216 | assert "validation_mode" in parsed |
215 | 217 | 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