Refactor geo caching and service layer tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-25 18:15:31 +02:00
parent 654dbdb000
commit d467190eb1
7 changed files with 218 additions and 150 deletions

View File

@@ -134,7 +134,7 @@ async def perf_db_path(tmp_path_factory: Any) -> str:
country_cycle = _COUNTRIES * (_BAN_COUNT // len(_COUNTRIES) + 1)
for i, ip in enumerate(ips):
cc, cn = country_cycle[i]
geo_service._cache[ip] = GeoInfo( # noqa: SLF001 (test-only direct access)
geo_service._default_geo_cache._cache[ip] = GeoInfo( # noqa: SLF001 (test-only direct access)
country_code=cc,
country_name=cn,
asn=f"AS{1000 + i % 500}",
@@ -158,7 +158,7 @@ class TestBanServicePerformance:
"""``list_bans`` with 10 000 bans completes in under 2 seconds."""
async def noop_enricher(ip: str) -> GeoInfo | None:
return geo_service._cache.get(ip) # noqa: SLF001
return geo_service._default_geo_cache._cache.get(ip) # noqa: SLF001
with patch(
"app.services.ban_service.get_fail2ban_db_path",
@@ -188,7 +188,7 @@ class TestBanServicePerformance:
"""``bans_by_country`` with 10 000 bans completes in under 2 seconds."""
async def noop_enricher(ip: str) -> GeoInfo | None:
return geo_service._cache.get(ip) # noqa: SLF001
return geo_service._default_geo_cache._cache.get(ip) # noqa: SLF001
with patch(
"app.services.ban_service.get_fail2ban_db_path",
@@ -214,7 +214,7 @@ class TestBanServicePerformance:
"""All returned items have geo data from the warm cache."""
async def noop_enricher(ip: str) -> GeoInfo | None:
return geo_service._cache.get(ip) # noqa: SLF001
return geo_service._default_geo_cache._cache.get(ip) # noqa: SLF001
with patch(
"app.services.ban_service.get_fail2ban_db_path",
@@ -238,7 +238,7 @@ class TestBanServicePerformance:
"""Country aggregation sums across all 10 000 bans."""
async def noop_enricher(ip: str) -> GeoInfo | None:
return geo_service._cache.get(ip) # noqa: SLF001
return geo_service._default_geo_cache._cache.get(ip) # noqa: SLF001
with patch(
"app.services.ban_service.get_fail2ban_db_path",