tests/: conftest.py - minimale Env-Vars + sys.path-Setup test_auth.py - Magic-Token + JWT Round-Trip (4 Tests) test_audit.py - diff() + _to_json() Helper (8 Tests) test_models.py - Pydantic-Validierung (7 Tests) test_source_meta.py - Single Source of Truth Konsistenz (7 Tests) test_imports.py - alle Backend-Module importierbar (4 Tests) requirements-dev.txt: pytest, ftfy, pyflakes Tests sind reine Unit-Tests (kein DB-Zugriff, kein HTTP-Server), laufen in <0.5s, geben sofortiges Catch-Net fuer Syntax/Import-Bugs. Aufruf: PYTHONPATH=src ./venv/bin/python -m pytest tests/ -v CLAUDE.md erweitert um: - Sektion Tests (Framework, Pfad, Ausfuehrung) - Sektion Phasen-Historie (alle 12 Phasen der Aufraeum-Aktion 2026-05-09 mit kurzer Erklaerung)
52 Zeilen
1.4 KiB
Python
52 Zeilen
1.4 KiB
Python
"""Tests fuer src/audit.py - diff() + _to_json() Helpers."""
|
|
import json
|
|
from audit import diff, _to_json
|
|
|
|
|
|
def test_diff_returns_only_changed_fields():
|
|
before = {"name": "Alt", "status": "active", "max_users": 5}
|
|
after = {"name": "Neu", "status": "active", "max_users": 5}
|
|
result = diff(before, after)
|
|
assert result == {"name": {"old": "Alt", "new": "Neu"}}
|
|
|
|
|
|
def test_diff_no_changes_returns_none():
|
|
same = {"a": 1, "b": "x"}
|
|
assert diff(same, dict(same)) is None
|
|
|
|
|
|
def test_diff_with_none_returns_none():
|
|
assert diff(None, {"a": 1}) is None
|
|
assert diff({"a": 1}, None) is None
|
|
|
|
|
|
def test_diff_added_or_removed_fields():
|
|
before = {"a": 1}
|
|
after = {"a": 1, "b": 2}
|
|
result = diff(before, after)
|
|
assert result == {"b": {"old": None, "new": 2}}
|
|
|
|
|
|
def test_to_json_handles_none():
|
|
assert _to_json(None) is None
|
|
|
|
|
|
def test_to_json_handles_dict():
|
|
out = _to_json({"x": 1, "y": "hallo"})
|
|
assert json.loads(out) == {"x": 1, "y": "hallo"}
|
|
|
|
|
|
def test_to_json_handles_non_serializable_via_str_default():
|
|
"""Custom Objekte werden via default=str zu Strings."""
|
|
class Foo:
|
|
def __str__(self):
|
|
return "FooObj"
|
|
out = _to_json({"obj": Foo()})
|
|
assert "FooObj" in out
|
|
|
|
|
|
def test_to_json_preserves_umlauts():
|
|
"""ensure_ascii=False soll deutsche Umlaute durchlassen."""
|
|
out = _to_json({"name": "Müller"})
|
|
assert "Müller" in out
|