113 lines
4.7 KiB
Python
113 lines
4.7 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
|
|
assert (await client.get("/api/projekte/Fremd/recherche")).status_code == 404
|
|
|
|
|
|
async def test_recherche_faeden(client, monkeypatch):
|
|
import agents
|
|
|
|
await client.post("/api/projekte", json={"name": "Alpha"})
|
|
assert (await client.get("/api/projekte/Alpha/recherche")).json()["faeden"] == []
|
|
|
|
a = (await client.post("/api/projekte/Alpha/recherche")).json()
|
|
b = (await client.post("/api/projekte/Alpha/recherche")).json()
|
|
assert a["id"] != b["id"]
|
|
|
|
async def antworte(system, inhalt, kommando=None, ordner=None):
|
|
return "## Festgelegt\n- **5 GB** je Sendung"
|
|
|
|
monkeypatch.setattr(agents, "frage_lokal", antworte)
|
|
res = await client.post(f"/api/projekte/Alpha/recherche/{a['id']}",
|
|
json={"text": "Was gilt?"})
|
|
assert res.json()["titel"] == "Was gilt?"
|
|
assert len(res.json()["verlauf"]) == 2
|
|
assert res.json()["verlauf"][-1]["text"] == "## Festgelegt\n- **5 GB** je Sendung"
|
|
|
|
# Der zweite Faden bleibt leer — Fäden teilen sich nichts
|
|
faeden = (await client.get("/api/projekte/Alpha/recherche")).json()["faeden"]
|
|
assert [len(f["verlauf"]) for f in faeden] == [2, 0]
|
|
|
|
assert (await client.delete(f"/api/projekte/Alpha/recherche/{b['id']}")).status_code == 200
|
|
assert len((await client.get("/api/projekte/Alpha/recherche")).json()["faeden"]) == 1
|
|
assert (await client.delete(f"/api/projekte/Alpha/recherche/{b['id']}")).status_code == 404
|
|
|
|
|
|
async def test_recherche_leere_frage(client):
|
|
await client.post("/api/projekte", json={"name": "Alpha"})
|
|
faden = (await client.post("/api/projekte/Alpha/recherche")).json()
|
|
res = await client.post(f"/api/projekte/Alpha/recherche/{faden['id']}",
|
|
json={"text": " "})
|
|
assert res.status_code == 400
|