From 58fc240e7dae3028838b8513f54da5297a32e489 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 4 Sep 2026 07:07:54 +0000 Subject: [PATCH] test(reputation): add test for read_and_parse in refresh_netsets Adds a dedicated unit test `test_refresh_netsets_read_and_parse` in `tests/test_reputation.py` to directly cover the inner function `read_and_parse()` of `refresh_netsets`. The test uses a mocked file layout and `unittest.mock.patch` on `pathlib.Path.read_text` to simulate reading a cached `.netset` file, bringing the coverage of `src/netsleuth/reputation.py` up to 100%. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_reputation.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_reputation.py b/tests/test_reputation.py index 09269a2..7671568 100644 --- a/tests/test_reputation.py +++ b/tests/test_reputation.py @@ -410,6 +410,25 @@ async def test_refresh_netsets_skips_list_on_http_error_if_no_cache_exists(httpx assert not (cache_dir / "firehol_level2.netset").exists() +async def test_refresh_netsets_read_and_parse(tmp_path, providers): + cache_dir = tmp_path / "firehol" + cache_dir.mkdir(parents=True, exist_ok=True) + + path = cache_dir / "firehol_level1.netset" + path.write_text("10.0.0.0/8\n", encoding="utf-8") + + # Restrict to only the provider we prepared + providers.firehol_netsets = ["http://example.com/firehol_level1.netset"] + + with patch("pathlib.Path.read_text", autospec=True) as mock_read: + mock_read.return_value = "192.168.0.0/16\n" + async with httpx.AsyncClient() as client: + index = await refresh_netsets(client, providers, tmp_path) + + mock_read.assert_called_once_with(path, encoding="utf-8") + assert index.hits("192.168.1.1") == ["firehol_level1"] + + def test_summarize_dnsbl_empty(): hits, blocked = summarize_dnsbl([]) assert hits == []