- Skip half_hour_report events from webhook posts in people_flow - Handle pre-existing stale worker status files during startup gracefully - Make store_dwell_alert timestamp parsing robust against invalid/empty values - Update lessons learned and todo documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from src.people_flow.webhook import dispatch_json_event
|
|
|
|
|
|
def test_dispatch_json_event_does_not_post_half_hour_report_but_keeps_local_log(
|
|
tmp_path, monkeypatch
|
|
):
|
|
sent: dict[str, object] = {}
|
|
|
|
class DummyResponse:
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, tb):
|
|
return False
|
|
|
|
def fake_urlopen(req, timeout):
|
|
sent["url"] = req.full_url
|
|
sent["timeout"] = timeout
|
|
sent["payload"] = json.loads(req.data.decode("utf-8"))
|
|
return DummyResponse()
|
|
|
|
monkeypatch.setattr("src.people_flow.webhook.request.urlopen", fake_urlopen)
|
|
|
|
output = tmp_path / "logs" / "events.jsonl"
|
|
payload = {
|
|
"event": "half_hour_report",
|
|
"total_people": 3,
|
|
"tracks": [
|
|
{"track_id": 1, "direction": "in"},
|
|
{"track_id": 2, "direction": "out"},
|
|
],
|
|
}
|
|
|
|
dispatch_json_event(
|
|
output,
|
|
payload,
|
|
webhook_url="https://example.test/webhook",
|
|
timeout_seconds=7.5,
|
|
)
|
|
|
|
lines = output.read_text(encoding="utf-8").splitlines()
|
|
assert json.loads(lines[0]) == payload
|
|
assert sent == {}
|