Refactor geo caching and service layer tests
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from app.models.geo import GeoDetail, GeoInfo
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_SETUP_PAYLOAD = {
|
||||
"master_password": "testpassword1",
|
||||
"master_password": "TestPassword1!",
|
||||
"database_path": "bangui.db",
|
||||
"fail2ban_socket": "/var/run/fail2ban/fail2ban.sock",
|
||||
"timezone": "UTC",
|
||||
@@ -46,6 +46,10 @@ async def geo_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
|
||||
app.state.db = db
|
||||
app.state.http_session = MagicMock()
|
||||
|
||||
# Initialize GeoCache (normally done in lifespan handler)
|
||||
from app.services.geo_cache import GeoCache
|
||||
app.state.geo_cache = GeoCache()
|
||||
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as ac:
|
||||
setup_payload = _SETUP_PAYLOAD.copy()
|
||||
@@ -198,9 +202,12 @@ class TestReResolve:
|
||||
await db.commit()
|
||||
|
||||
geo_result = {"5.5.5.5": GeoInfo(country_code="FR", country_name="France", asn=None, org=None)}
|
||||
with patch(
|
||||
"app.routers.geo.geo_service.lookup_batch",
|
||||
AsyncMock(return_value=geo_result),
|
||||
# Patch the default geo_cache instance used by geo_service
|
||||
from app.services.geo_service import _default_geo_cache
|
||||
with patch.object(
|
||||
_default_geo_cache,
|
||||
"lookup_batch",
|
||||
new_callable=lambda: AsyncMock(return_value=geo_result),
|
||||
):
|
||||
resp = await geo_client.post("/api/geo/re-resolve")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user