Files
crucible-agent-build-fastap…/tests/test_api.py

33 lines
1.4 KiB
Python

from uuid import uuid4
from fastapi.testclient import TestClient
def create(client: TestClient, url: str = "https://example.com/health") -> dict[str, object]:
response = client.post("/v1/monitors", json={"name": "site", "url": url})
assert response.status_code == 201
return response.json()
def test_crud_and_operational_routes(client: TestClient) -> None:
assert client.get("/healthz").json() == {"status": "ok"}
assert client.get("/readyz").json() == {"status": "ready"}
item = create(client)
monitor_id = item["id"]
assert item["current_status"]["state"] == "unknown"
assert len(client.get("/v1/monitors").json()) == 1
updated = client.patch(f"/v1/monitors/{monitor_id}", json={"name": "new"})
assert updated.status_code == 200
assert updated.json()["name"] == "new"
assert client.get(f"/v1/monitors/{monitor_id}/status").json()["state"] == "unknown"
assert client.delete(f"/v1/monitors/{monitor_id}").status_code == 204
assert client.get(f"/v1/monitors/{monitor_id}").status_code == 404
def test_validation_and_missing(client: TestClient) -> None:
assert client.post("/v1/monitors", json={"name": "", "url": "file:///tmp/x"}).status_code == 422
missing = uuid4()
assert client.get(f"/v1/monitors/{missing}").json() == {"detail": "monitor not found"}
item = create(client)
assert client.patch(f"/v1/monitors/{item['id']}", json={}).status_code == 422