from __future__ import annotations import json from src.people_flow.webhook import dispatch_json_event def test_dispatch_json_event_omits_tracks_from_webhook_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["url"] == "https://example.test/webhook" assert sent["timeout"] == 7.5 assert sent["payload"] == { "event": "half_hour_report", "total_people": 3, }