41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
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 |