fixed tests
This commit is contained in:
@@ -30,13 +30,17 @@ _SETUP_PAYLOAD = {
|
||||
@pytest.fixture
|
||||
async def geo_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
|
||||
"""Provide an authenticated ``AsyncClient`` for geo endpoint tests."""
|
||||
config_dir = tmp_path / "fail2ban"
|
||||
config_dir.mkdir()
|
||||
settings = Settings(
|
||||
database_path=str(tmp_path / "geo_test.db"),
|
||||
fail2ban_socket="/tmp/fake.sock",
|
||||
session_secret="test-geo-secret",
|
||||
fail2ban_config_dir=str(config_dir),
|
||||
session_secret="test-geo-secret-that-is-long-enough!!",
|
||||
session_duration_minutes=60,
|
||||
timezone="UTC",
|
||||
log_level="debug",
|
||||
session_cookie_secure=False,
|
||||
)
|
||||
app = create_app(settings=settings)
|
||||
|
||||
@@ -48,6 +52,7 @@ async def geo_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
|
||||
|
||||
# Initialize GeoCache (normally done in lifespan handler)
|
||||
from app.services.geo_cache import GeoCache
|
||||
|
||||
app.state.geo_cache = GeoCache()
|
||||
|
||||
transport = ASGITransport(app=app)
|
||||
@@ -179,7 +184,10 @@ class TestReResolve:
|
||||
"app.routers.geo.geo_service.re_resolve_all",
|
||||
AsyncMock(return_value={"resolved": 0, "total": 0}),
|
||||
):
|
||||
resp = await geo_client.post("/api/v1/geo/re-resolve")
|
||||
resp = await geo_client.post(
|
||||
"/api/v1/geo/re-resolve",
|
||||
headers={"X-BanGUI-Request": "1"},
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
@@ -188,7 +196,10 @@ class TestReResolve:
|
||||
|
||||
async def test_empty_when_no_unresolved_ips(self, geo_client: AsyncClient) -> None:
|
||||
"""Returns resolved=0, total=0 when geo_cache has no NULL country_code rows."""
|
||||
resp = await geo_client.post("/api/v1/geo/re-resolve")
|
||||
resp = await geo_client.post(
|
||||
"/api/v1/geo/re-resolve",
|
||||
headers={"X-BanGUI-Request": "1"},
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == {"resolved": 0, "total": 0}
|
||||
@@ -204,12 +215,16 @@ class TestReResolve:
|
||||
geo_result = {"5.5.5.5": GeoInfo(country_code="FR", country_name="France", asn=None, org=None)}
|
||||
# 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/v1/geo/re-resolve")
|
||||
resp = await geo_client.post(
|
||||
"/api/v1/geo/re-resolve",
|
||||
headers={"X-BanGUI-Request": "1"},
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
|
||||
Reference in New Issue
Block a user