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)
54 Zeilen
1.7 KiB
Python
54 Zeilen
1.7 KiB
Python
"""Tests fuer src/models.py - Pydantic-Validierung."""
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from models import (
|
|
MagicLinkRequest, MagicLinkResponse,
|
|
VerifyTokenRequest, TokenResponse,
|
|
OrgCreate, LicenseCreate, UserCreate,
|
|
)
|
|
|
|
|
|
def test_magic_link_request_accepts_email():
|
|
r = MagicLinkRequest(email="info@aegis-sight.de")
|
|
assert r.email == "info@aegis-sight.de"
|
|
|
|
|
|
def test_magic_link_request_rejects_too_short():
|
|
with pytest.raises(ValidationError):
|
|
MagicLinkRequest(email="a")
|
|
|
|
|
|
def test_verify_token_min_length():
|
|
with pytest.raises(ValidationError):
|
|
VerifyTokenRequest(token="abc")
|
|
|
|
|
|
def test_token_response_default_email_empty():
|
|
r = TokenResponse(access_token="x" * 40, username="info")
|
|
assert r.email == ""
|
|
assert r.token_type == "bearer"
|
|
|
|
|
|
def test_org_create_slug_pattern():
|
|
"""Slug muss lowercase mit Bindestrichen sein."""
|
|
OrgCreate(name="Test", slug="abc-123")
|
|
with pytest.raises(ValidationError):
|
|
OrgCreate(name="Test", slug="Wrong Case")
|
|
with pytest.raises(ValidationError):
|
|
OrgCreate(name="Test", slug="under_score")
|
|
|
|
|
|
def test_license_create_type_pattern():
|
|
LicenseCreate(organization_id=1, license_type="trial")
|
|
LicenseCreate(organization_id=1, license_type="annual")
|
|
LicenseCreate(organization_id=1, license_type="permanent")
|
|
with pytest.raises(ValidationError):
|
|
LicenseCreate(organization_id=1, license_type="lifetime")
|
|
|
|
|
|
def test_user_create_role_pattern():
|
|
UserCreate(email="a@b.de", role="member")
|
|
UserCreate(email="a@b.de", role="org_admin")
|
|
with pytest.raises(ValidationError):
|
|
UserCreate(email="a@b.de", role="superuser")
|