Standardize API response envelopes: use items for collection responses and update tests

This commit is contained in:
2026-04-28 20:48:00 +02:00
parent 1c673d600c
commit b27765928a
23 changed files with 186 additions and 104 deletions

View File

@@ -47,6 +47,7 @@ async def config_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
session_duration_minutes=60,
timezone="UTC",
log_level="debug",
session_cookie_secure=False,
)
app = create_app(settings=settings)
@@ -98,7 +99,7 @@ class TestGetJailConfigs:
async def test_200_returns_jail_list(self, config_client: AsyncClient) -> None:
"""GET /api/config/jails returns 200 with JailConfigListResponse."""
mock_response = JailConfigListResponse(
jails=[_make_jail_config("sshd")], total=1
items=[_make_jail_config("sshd")], total=1
)
with patch(
"app.routers.jail_config.config_service.list_jail_configs",
@@ -109,7 +110,7 @@ class TestGetJailConfigs:
assert resp.status_code == 200
data = resp.json()
assert data["total"] == 1
assert data["jails"][0]["name"] == "sshd"
assert data["items"][0]["name"] == "sshd"
async def test_401_when_unauthenticated(self, config_client: AsyncClient) -> None:
"""GET /api/config/jails returns 401 without a valid session."""
@@ -694,7 +695,7 @@ class TestGetInactiveJails:
source_file="/etc/fail2ban/jail.conf",
enabled=False,
)
mock_response = InactiveJailListResponse(jails=[mock_jail], total=1)
mock_response = InactiveJailListResponse(items=[mock_jail], total=1)
with patch(
"app.routers.jail_config.jail_config_service.list_inactive_jails",
@@ -705,7 +706,7 @@ class TestGetInactiveJails:
assert resp.status_code == 200
data = resp.json()
assert data["total"] == 1
assert data["jails"][0]["name"] == "apache-auth"
assert data["items"][0]["name"] == "apache-auth"
async def test_200_empty_list(self, config_client: AsyncClient) -> None:
"""GET /api/config/jails/inactive returns 200 with empty list."""
@@ -713,13 +714,13 @@ class TestGetInactiveJails:
with patch(
"app.routers.jail_config.jail_config_service.list_inactive_jails",
AsyncMock(return_value=InactiveJailListResponse(jails=[], total=0)),
AsyncMock(return_value=InactiveJailListResponse(items=[], total=0)),
):
resp = await config_client.get("/api/config/jails/inactive")
assert resp.status_code == 200
assert resp.json()["total"] == 0
assert resp.json()["jails"] == []
assert resp.json()["items"] == []
async def test_401_when_unauthenticated(self, config_client: AsyncClient) -> None:
"""GET /api/config/jails/inactive returns 401 without a valid session."""