This commit is contained in:
Team3
2026-07-26 20:53:01 +02:00
parent ebfb2fc360
commit 0115fd4ce9
13 changed files with 264 additions and 321 deletions

View File

@@ -63,11 +63,11 @@ def _folge_titel(datei, titel: str):
def speichern(projekt: str, id: str, roh: str) -> dict:
datei = _datei(projekt, id)
datei.write_text(roh)
titel = parser.zerlege(roh)["titel"]
if titel:
datei = _folge_titel(datei, titel)
return _eintrag(datei)
if not titel:
raise ValueError("Titel fehlt")
datei.write_text(roh)
return _eintrag(_folge_titel(datei, titel))
def loeschen(projekt: str, id: str):

View File

@@ -24,10 +24,7 @@ def liste() -> list[dict]:
(p for p in config.DATEN_DIR.iterdir() if p.is_dir()),
key=lambda p: p.name.lower(),
)
return [
{"name": p.name, "anzahl": len(list(p.glob("*.md")))}
for p in ordner
]
return [{"name": p.name} for p in ordner]
def anlegen(name: str):

View File

@@ -74,8 +74,10 @@ async def feature_anlegen(name: str, body: dict):
async def feature_speichern(name: str, id: str, body: dict):
try:
return features.speichern(name, id, body.get("roh") or "")
except (FileNotFoundError, ValueError) as e:
except FileNotFoundError as e:
raise HTTPException(404, str(e))
except ValueError as e:
raise HTTPException(400, str(e))
@router.delete("/projekte/{name}/features/{id}")

View File

@@ -70,6 +70,12 @@ def test_loeschen(projekt):
assert features.liste(projekt) == []
def test_speichern_ohne_titel(projekt):
f = features.anlegen(projekt, "<!-- titel -->\nDa\n")
with pytest.raises(ValueError):
features.speichern(projekt, f["id"], "<!-- ziel -->\nohne Titel\n")
def test_unbekannte_id(projekt):
with pytest.raises(FileNotFoundError):
features.speichern(projekt, "gibts-nicht", "x")

View File

@@ -43,6 +43,10 @@ async def test_feature_crud(client):
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"