Milestone 1.

This commit is contained in:
2025-08-18 20:14:56 +02:00
parent 9d1623c739
commit 1646d7b827
23 changed files with 1684 additions and 1275 deletions

41
tests/test_notes_fs.py Normal file
View File

@@ -0,0 +1,41 @@
import os
import uuid
from app.services.notes_fs import create_note, list_notes, load_note_by_id
from app.utils.time import is_iso_utc
from app import create_app
def test_create_and_load_note(tmp_path, monkeypatch):
vault = tmp_path / "vault"
os.makedirs(vault, exist_ok=True)
# Configure app with temporary vault
app = create_app(type("Cfg", (), {"VAULT_PATH": str(vault), "SECRET_KEY": "x", "DEBUG": False})())
with app.app_context():
n = create_note(title="My Test Note", body="Body", tags=["t1", "t2"])
assert n.title == "My Test Note"
assert is_iso_utc(n.created)
assert is_iso_utc(n.updated)
# File exists
assert (vault / n.rel_path).exists()
# List and find by id
notes = list_notes()
assert any(x.id == n.id for x in notes)
n2 = load_note_by_id(n.id)
assert n2 is not None
assert n2.title == "My Test Note"
assert n2.body == "Body"
assert n2.tags == ["t1", "t2"]
def test_load_note_by_id_missing(tmp_path):
vault = tmp_path / "vault"
os.makedirs(vault, exist_ok=True)
app = create_app(type("Cfg", (), {"VAULT_PATH": str(vault), "SECRET_KEY": "x", "DEBUG": False})())
with app.app_context():
assert load_note_by_id(str(uuid.uuid4())) is None

20
tests/test_slugs.py Normal file
View File

@@ -0,0 +1,20 @@
from app.utils.slugs import slugify
def test_slugify_basic():
assert slugify("Hello World") == "hello-world"
assert slugify("Hello World!!!") == "hello-world"
assert slugify("Café au lait") == "cafe-au-lait"
assert slugify("123 Numbers First") == "123-numbers-first"
def test_slugify_length():
long = "A" * 200
s = slugify(long, max_length=32)
assert len(s) <= 32
assert s.startswith("a")
def test_slugify_empty():
assert slugify("") == "untitled"
assert slugify("!!!") == "untitled"