From 39ae6e4c64d7ce244e4868660ac16f6905d6ebf8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:03:54 +0000 Subject: [PATCH] test(bgp): add edge case tests for parse_peeringdb_netixlan Adds explicit test cases for `parse_peeringdb_netixlan` to cover empty payloads, missing keys, and items with a false operational status. This increases test coverage and reliability of the data transformation logic. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_bgp.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_bgp.py b/tests/test_bgp.py index 202fddc..ec7837e 100644 --- a/tests/test_bgp.py +++ b/tests/test_bgp.py @@ -156,6 +156,39 @@ def test_peeringdb_netixlan_lists_only_operational_exchanges(api_fixture): assert ixps[1].speed_mbps == 200000 +def test_peeringdb_netixlan_of_an_empty_payload(): + assert parse_peeringdb_netixlan({}) == [] + assert parse_peeringdb_netixlan({"data": None}) == [] + assert parse_peeringdb_netixlan({"data": []}) == [] + + +def test_peeringdb_netixlan_ignores_non_operational_entries(): + payload = { + "data": [ + {"name": "IXP 1", "operational": True}, + {"name": "IXP 2", "operational": False}, + {"name": "IXP 3"}, + ] + } + ixps = parse_peeringdb_netixlan(payload) + assert len(ixps) == 1 + assert ixps[0].name == "IXP 1" + + +def test_peeringdb_netixlan_handles_missing_keys(): + payload = { + "data": [ + {"operational": True} + ] + } + ixps = parse_peeringdb_netixlan(payload) + assert len(ixps) == 1 + assert ixps[0].name == "" + assert ixps[0].city is None + assert ixps[0].country is None + assert ixps[0].speed_mbps is None + + async def test_cached_json_writes_then_reuses_the_cache(tmp_path: Path): calls = []