mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 22:42:03 +03:00
🧪 Add test for WatchSession.to_report
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>
This commit is contained in:
parent
8c99ac78b7
commit
d6cbda6138
1 changed files with 29 additions and 0 deletions
|
|
@ -196,3 +196,32 @@ def test_render_dashboard_with_speed_results():
|
||||||
table = render_dashboard(session)
|
table = render_dashboard(session)
|
||||||
|
|
||||||
assert "last speedtest: 284.3 / 41.7 Mbps via cloudflare · bufferbloat B" in table.caption
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue