33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
import httpx
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.anyio
|
|
|
|
|
|
async def test_crud_status_and_operations(client: httpx.AsyncClient) -> None:
|
|
created = await client.post("/monitors", json={"name": "site", "url": "https://example.com/a"})
|
|
assert created.status_code == 201
|
|
monitor = created.json()
|
|
monitor_id = monitor["id"]
|
|
assert monitor["status"]["state"] == "unknown"
|
|
assert (await client.get("/monitors")).json()[0]["id"] == monitor_id
|
|
assert (await client.get(f"/monitors/{monitor_id}")).status_code == 200
|
|
|
|
updated = await client.put(
|
|
f"/monitors/{monitor_id}",
|
|
json={"name": "new", "url": "https://example.org/"},
|
|
)
|
|
assert updated.status_code == 200
|
|
assert updated.json()["status"]["state"] == "unknown"
|
|
assert (await client.get(f"/monitors/{monitor_id}/status")).status_code == 200
|
|
assert (await client.delete(f"/monitors/{monitor_id}")).status_code == 204
|
|
assert (await client.get(f"/monitors/{monitor_id}")).status_code == 404
|
|
|
|
assert (await client.get("/health/live")).json() == {"status": "ok"}
|
|
assert (await client.get("/health/ready")).json() == {"status": "ready"}
|
|
|
|
|
|
async def test_validation_and_missing(client: httpx.AsyncClient) -> None:
|
|
assert (await client.post("/monitors", json={"name": "", "url": "file:///x"})).status_code == 422
|
|
assert (await client.get("/monitors/00000000-0000-0000-0000-000000000000")).status_code == 404
|