init
This commit is contained in:
59
backend/tests/test_routes.py
Normal file
59
backend/tests/test_routes.py
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
|
||||
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_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
|
||||
Reference in New Issue
Block a user