Files
planer2/backend/tests/test_routes.py
2026-07-27 11:29:57 +02:00

75 lines
3.0 KiB
Python

ROH = "<!-- titel -->\nLogin\n<!-- funktion -->\nAnmeldung\n<!-- regel -->\nPasswort nie loggen\n"
async def test_health(client):
res = await client.get("/api/health")
assert res.status_code == 200
assert res.json() == {"ok": True}
async def test_projekt_crud(client):
assert (await client.get("/api/projekte")).json() == []
res = await client.post("/api/projekte", json={"name": "Alpha"})
assert res.status_code == 200
# Duplikat → 409, ungültig → 400
assert (await client.post("/api/projekte", json={"name": "Alpha"})).status_code == 409
assert (await client.post("/api/projekte", json={"name": ""})).status_code == 400
assert (await client.post("/api/projekte", json={"name": "../boese"})).status_code == 400
res = await client.put("/api/projekte/Alpha", json={"name": "Beta"})
assert res.status_code == 200
assert res.json() == {"name": "Beta"}
assert (await client.put("/api/projekte/Alpha", json={"name": "X"})).status_code == 404
assert [p["name"] for p in (await client.get("/api/projekte")).json()] == ["Beta"]
assert (await client.delete("/api/projekte/Beta")).status_code == 200
assert (await client.delete("/api/projekte/Beta")).status_code == 404
async def test_feature_crud(client):
await client.post("/api/projekte", json={"name": "Alpha"})
res = await client.post("/api/projekte/Alpha/features", json={"roh": ROH})
assert res.status_code == 200
f = res.json()
assert f["id"] == "login"
assert f["roh"] == ROH
assert f["sektionen"]["titel"] == "Login"
# Titel fehlt → 400
res = await client.post("/api/projekte/Alpha/features", json={"roh": "kein Titel"})
assert res.status_code == 400
# Titel fehlt → 400
res = await client.put("/api/projekte/Alpha/features/login", json={"roh": "kein Titel"})
assert res.status_code == 400
res = await client.put("/api/projekte/Alpha/features/login", json={"roh": "mehr\n" + ROH})
assert res.status_code == 200
assert res.json()["sektionen"]["sonstiges"] == "mehr"
liste = (await client.get("/api/projekte/Alpha/features")).json()
assert len(liste) == 1
assert (await client.delete("/api/projekte/Alpha/features/login")).status_code == 200
assert (await client.delete("/api/projekte/Alpha/features/login")).status_code == 404
async def test_pruefung_ohne_konfiguration(client, monkeypatch):
import agents
monkeypatch.setattr(agents.config, "MINIMAX_API_KEY", "")
await client.post("/api/projekte", json={"name": "Alpha"})
res = await client.post("/api/projekte/Alpha/pruefung")
# 400, nicht 409 — 409 heißt „läuft bereits" und würde die Meldung verschlucken
assert res.status_code == 400
assert "MINIMAX_API_KEY" in res.json()["detail"]
async def test_unbekanntes_projekt(client):
assert (await client.get("/api/projekte/Fremd/features")).status_code == 404
assert (await client.post("/api/projekte/Fremd/features", json={"roh": ROH})).status_code == 404