Use dependency injection for health status and add health router regression test
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from app.models.server import ServerStatus
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_check_returns_200(client: AsyncClient) -> None:
|
||||
@@ -25,3 +27,14 @@ async def test_health_check_content_type_is_json(client: AsyncClient) -> None:
|
||||
"""``GET /api/health`` must set the ``Content-Type`` header to JSON."""
|
||||
response = await client.get("/api/health")
|
||||
assert "application/json" in response.headers.get("content-type", "")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_check_respects_cached_server_status(client: AsyncClient) -> None:
|
||||
"""The health response should reflect the injected cached server status."""
|
||||
client._transport.app.state.server_status = ServerStatus(online=True)
|
||||
|
||||
response = await client.get("/api/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["fail2ban"] == "online"
|
||||
|
||||
Reference in New Issue
Block a user