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

36 lines
1.6 KiB
Python

import httpx
import pytest
@pytest.mark.anyio
async def test_crud_check_status_and_operations(client: httpx.AsyncClient) -> None:
created = await client.post("/monitors", json={"name": "Example", "url": "https://example.com/a?token=secret"})
assert created.status_code == 201
monitor_id = created.json()["id"]
assert created.json()["status"]["state"] == "unknown"
assert (await client.get("/monitors")).json()[0]["name"] == "Example"
changed = await client.patch(f"/monitors/{monitor_id}", json={"name": "Changed"})
assert changed.status_code == 200
assert changed.json()["name"] == "Changed"
checked = await client.post(f"/monitors/{monitor_id}/check")
assert checked.status_code == 200
assert checked.json()["status"]["state"] == "up"
assert "token" not in checked.json()["url"]
assert (await client.get(f"/monitors/{monitor_id}/status")).json()["http_status"] == 204
assert (await client.get("/healthz")).json() == {"status": "ok"}
assert (await client.get("/readyz")).status_code == 200
assert (await client.delete(f"/monitors/{monitor_id}")).status_code == 204
missing = await client.get(f"/monitors/{monitor_id}")
assert missing.status_code == 404
assert missing.json()["error"]["code"] == "http_404"
@pytest.mark.anyio
async def test_validation_error_has_contract_shape(client: httpx.AsyncClient) -> None:
response = await client.post("/monitors", json={"name": "", "url": "file:///etc/passwd"})
assert response.status_code == 422
assert response.json()["error"]["code"] == "validation_error"