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, "\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, "\nGleich\n") b = features.anlegen(projekt, "\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, "\nAlt\n") g = features.speichern(projekt, f["id"], "\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, "\nZiel\n") f = features.anlegen(projekt, "\nAnders\n") g = features.speichern(projekt, f["id"], "\nZiel\n") assert g["id"] == "ziel-2" def test_gleicher_titel_behaelt_kollisions_suffix(projekt): features.anlegen(projekt, "\nGleich\n") f = features.anlegen(projekt, "\nGleich\n") g = features.speichern(projekt, f["id"], "\nGleich\n\nx\n") assert g["id"] == "gleich-2" def test_speichern_verbatim(projekt, datenordner): f = features.anlegen(projekt, "\nX\n") roh = "Vorspann\n\nX\n\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, "\nZebra\n") features.anlegen(projekt, "\nanton\n") titel = [f["sektionen"]["titel"] for f in features.liste(projekt)] assert titel == ["anton", "Zebra"] def test_loeschen(projekt): f = features.anlegen(projekt, "\nWeg\n") features.loeschen(projekt, f["id"]) assert features.liste(projekt) == [] def test_speichern_ohne_titel(projekt): f = features.anlegen(projekt, "\nDa\n") with pytest.raises(ValueError): features.speichern(projekt, f["id"], "\nohne Titel\n") 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")