Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyrit/cli/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ async def health_check_async(self) -> bool:
try:
client = self._get_client()
resp = await client.get("/api/health")
return resp.status_code == 200
if resp.status_code != 200:
return False
payload = resp.json()
return payload.get("status") == "healthy" and payload.get("service") == "pyrit-backend"
except httpx.ConnectError:
return False
except Exception:
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/cli/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,22 @@ def test_get_client_raises_when_not_opened():


async def test_health_check_returns_true_on_200(client, mock_httpx_client):
mock_httpx_client.get.return_value = _make_response(status_code=200)
mock_httpx_client.get.return_value = _make_response(
status_code=200,
json_data={"status": "healthy", "service": "pyrit-backend"},
)
assert await client.health_check_async() is True
mock_httpx_client.get.assert_awaited_once_with("/api/health")


async def test_health_check_returns_false_for_unrelated_service(client, mock_httpx_client):
mock_httpx_client.get.return_value = _make_response(
status_code=200,
json_data={"status": "ok", "service": "another-service"},
)
assert await client.health_check_async() is False


async def test_health_check_returns_false_on_non_200(client, mock_httpx_client):
mock_httpx_client.get.return_value = _make_response(status_code=503)
assert await client.health_check_async() is False
Expand Down