From d6cbda6138680066106972b380020ff0e9a56ad5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 03:54:50 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20test=20for=20WatchSession.?= =?UTF-8?q?to=5Freport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds missing unit test coverage for the pure data transformation method `WatchSession.to_report` in `src/netsleuth/watch.py`. The new test ensures that the resulting dictionary correctly maps internal session attributes, such as metadata, generated timestamps, and collected cycle metrics, maintaining expected schema compliance. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_watch.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_watch.py b/tests/test_watch.py index 16744a7..a5b2234 100644 --- a/tests/test_watch.py +++ b/tests/test_watch.py @@ -196,3 +196,32 @@ def test_render_dashboard_with_speed_results(): table = render_dashboard(session) assert "last speedtest: 284.3 / 41.7 Mbps via cloudflare ยท bufferbloat B" in table.caption + + +def test_watch_session_to_report(): + session = WatchSession( + started_at="2026-08-08T19:12:00Z", + asn="AS12345", + interval_seconds=60, + speedtest_every_n_cycles=10, + interface="eth0", + bind_ipv4="1.2.3.4", + alerts_fired=2, + ) + session.add(summarize_cycle(1, "2026-08-08T19:12:00Z", [ping("cloudflare-dns", 12.4)], None)) + + report = session.to_report() + + assert report["schema_version"] == WATCH_SCHEMA_VERSION + assert report["kind"] == "watch" + assert report["meta"]["started_at"] == "2026-08-08T19:12:00Z" + assert "finished_at" in report["meta"] + assert report["meta"]["asn"] == "AS12345" + assert report["meta"]["interval_seconds"] == 60 + assert report["meta"]["speedtest_every_n_cycles"] == 10 + assert report["meta"]["cycle_count"] == 1 + assert report["meta"]["interface"] == "eth0" + assert report["meta"]["bind_ipv4"] == "1.2.3.4" + assert report["meta"]["alerts_fired"] == 2 + assert len(report["cycles"]) == 1 + assert report["cycles"][0]["cycle"] == 1