Files
planer2/backend/tests/test_features.py
2026-07-24 22:39:23 +02:00

81 lines
2.6 KiB
Python

import pytest
import features
import projekte
@pytest.fixture
def projekt(datenordner):
projekte.anlegen("Test")
return "Test"
def test_anlegen_erzeugt_slug(projekt, datenordner):
f = features.anlegen(projekt, "<!-- titel -->\nÜber Ätzend!\n")
assert f["id"] == "ueber-aetzend"
assert (datenordner / "Test" / "ueber-aetzend.md").is_file()
def test_slug_kollision(projekt):
a = features.anlegen(projekt, "<!-- titel -->\nGleich\n")
b = features.anlegen(projekt, "<!-- titel -->\nGleich\n")
assert a["id"] == "gleich"
assert b["id"] == "gleich-2"
def test_titel_pflicht(projekt):
with pytest.raises(ValueError):
features.anlegen(projekt, "nur Text ohne Titel-Marker")
def test_titelaenderung_benennt_datei_um(projekt, datenordner):
f = features.anlegen(projekt, "<!-- titel -->\nAlt\n")
g = features.speichern(projekt, f["id"], "<!-- titel -->\nNeu\n")
assert g["id"] == "neu"
assert not (datenordner / "Test" / "alt.md").exists()
assert (datenordner / "Test" / "neu.md").is_file()
def test_umbenennen_mit_kollision(projekt):
features.anlegen(projekt, "<!-- titel -->\nZiel\n")
f = features.anlegen(projekt, "<!-- titel -->\nAnders\n")
g = features.speichern(projekt, f["id"], "<!-- titel -->\nZiel\n")
assert g["id"] == "ziel-2"
def test_gleicher_titel_behaelt_kollisions_suffix(projekt):
features.anlegen(projekt, "<!-- titel -->\nGleich\n")
f = features.anlegen(projekt, "<!-- titel -->\nGleich\n")
g = features.speichern(projekt, f["id"], "<!-- titel -->\nGleich\n<!-- ziel -->\nx\n")
assert g["id"] == "gleich-2"
def test_speichern_verbatim(projekt, datenordner):
f = features.anlegen(projekt, "<!-- titel -->\nX\n")
roh = "Vorspann\n<!-- titel -->\nX\n<!-- fremd -->\n unangetastet \n"
features.speichern(projekt, f["id"], roh)
assert (datenordner / "Test" / "x.md").read_text() == roh
def test_liste_sortiert_nach_titel(projekt):
features.anlegen(projekt, "<!-- titel -->\nZebra\n")
features.anlegen(projekt, "<!-- titel -->\nanton\n")
titel = [f["sektionen"]["titel"] for f in features.liste(projekt)]
assert titel == ["anton", "Zebra"]
def test_loeschen(projekt):
f = features.anlegen(projekt, "<!-- titel -->\nWeg\n")
features.loeschen(projekt, f["id"])
assert features.liste(projekt) == []
def test_unbekannte_id(projekt):
with pytest.raises(FileNotFoundError):
features.speichern(projekt, "gibts-nicht", "x")
def test_unbekanntes_projekt(datenordner):
with pytest.raises(FileNotFoundError):
features.liste("Fremd")