Skip to content

Commit 3e307ec

Browse files
committed
Fix Storebaelt freshness field order
1 parent c1287cc commit 3e307ec

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

publishers/storebaelt_webcams/storebaelt_webcams_publisher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def _apply_freshness_status(self, camera_id: str, latest: dict, poll_time: datet
265265
else:
266266
staleness_status = "unchanged"
267267

268+
source_url = result.pop("sourceUrl", "")
268269
result.update({
269270
"imageChanged": image_changed,
270271
"firstSeenTime": first_seen,
@@ -274,6 +275,7 @@ def _apply_freshness_status(self, camera_id: str, latest: dict, poll_time: datet
274275
"stalenessStatus": staleness_status,
275276
"sourceAgeSeconds": source_age_seconds,
276277
})
278+
result["sourceUrl"] = source_url
277279
self._image_state[camera_id] = {
278280
"imageSha256": image_sha256,
279281
"firstSeenTime": first_seen,

tests/test_storebaelt_webcams_publisher.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ def test_freshness_status_tracks_changed_and_unchanged_images():
116116
assert second["result"]["lastChangedTime"] == "2026-06-03T12:00:00Z"
117117

118118

119+
def test_freshness_fields_are_emitted_before_source_url_for_strict_swe_order():
120+
publisher = StorebaeltWebcamsPublisher.__new__(StorebaeltWebcamsPublisher)
121+
publisher._image_state = {}
122+
publisher._stale_seconds = 900
123+
latest = {
124+
"phenomenonTime": "2026-06-03T12:00:00Z",
125+
"dedupeKey": "sprogo|abc",
126+
"result": {"cameraId": "sprogo", "imageSha256": "abc", "sourceUrl": "https://example.test/image.jpg"},
127+
}
128+
129+
updated = publisher._apply_freshness_status("sprogo", latest, datetime(2026, 6, 3, 12, 0, tzinfo=timezone.utc))
130+
keys = list(updated["result"].keys())
131+
132+
assert keys.index("imageChanged") < keys.index("sourceUrl")
133+
assert keys.index("sourceAgeSeconds") < keys.index("sourceUrl")
134+
assert updated["result"]["sourceUrl"] == "https://example.test/image.jpg"
135+
136+
119137
def test_freshness_status_marks_stale_after_threshold():
120138
publisher = StorebaeltWebcamsPublisher.__new__(StorebaeltWebcamsPublisher)
121139
publisher._image_state = {

0 commit comments

Comments
 (0)