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

@@ -673,8 +673,9 @@ class TestOriginFilter:
await _create_f2b_db(path, rows)
from app.services import geo_service
from app.models.geo import GeoInfo
geo_service._cache["10.0.0.1"] = geo_service.GeoInfo(
geo_service._default_geo_cache._cache["10.0.0.1"] = GeoInfo(
country_code="DE",
country_name="Germany",
asn=None,
@@ -733,15 +734,16 @@ class TestBansbyCountryBackground:
"""When all IPs are in the cache, lookup_cached_only returns them and
no background task is created."""
from app.services import geo_service
from app.models.geo import GeoInfo
# Pre-populate the cache for all three IPs in the fixture.
geo_service._cache["10.0.0.1"] = geo_service.GeoInfo(
geo_service._default_geo_cache._cache["10.0.0.1"] = GeoInfo(
country_code="DE", country_name="Germany", asn=None, org=None
)
geo_service._cache["10.0.0.2"] = geo_service.GeoInfo(
geo_service._default_geo_cache._cache["10.0.0.2"] = GeoInfo(
country_code="US", country_name="United States", asn=None, org=None
)
geo_service._cache["10.0.0.3"] = geo_service.GeoInfo(
geo_service._default_geo_cache._cache["10.0.0.3"] = GeoInfo(
country_code="JP", country_name="Japan", asn=None, org=None
)