"""The AppError → HTML error-page handler: 404 for missing, 409 for duplicate."""

from __future__ import annotations

from fastapi.testclient import TestClient

_VM = {"name": "dup", "flavor": "a2-ram2-disk20", "image": "ubuntu-24.04"}


def test_missing_vm_renders_404(client: TestClient) -> None:
    resp = client.get("/vms/does-not-exist")
    assert resp.status_code == 404
    assert "text/html" in resp.headers["content-type"]


def test_duplicate_vm_renders_409(client: TestClient) -> None:
    assert client.post("/vms", data=_VM, follow_redirects=False).status_code == 303
    resp = client.post("/vms", data=_VM, follow_redirects=False)
    assert resp.status_code == 409
