Dateien
AegisSight-Monitor-Verwaltung/tests/test_models.py
claude-dev 9bf3adbacb feat(abrechnung): Credits-Uebertrag komplett entfernt
Produktentscheidung 07/2026: ungenutzte Credits verfallen zum
Periodenende. Uebertrag-Checkbox aus allen drei Formularen
(Kontingent bearbeiten, Lizenz anlegen, Org anlegen) samt
Ausgrau-Logik raus, credits_rollover/credits_carried aus Modellen,
Endpoints (overview/current/PUT budget) und insert_license_row raus,
Anzeige inkl. Uebertrag im Org-Detail raus. Migrationsskript legt die
beiden Spalten nicht mehr an. Gegenstueck zum Monitor-Commit f8499c4,
Promote-Reihenfolge wie immer Monitor VOR Portal.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-25 21:51:02 +00:00

113 Zeilen
3.8 KiB
Python

"""Tests fuer src/models.py - Pydantic-Validierung."""
import pytest
from pydantic import ValidationError
from models import (
MagicLinkRequest, MagicLinkResponse,
VerifyTokenRequest, TokenResponse,
OrgCreate, LicenseCreate, LicenseParams, LicenseResponse, 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_license_params_credits_defaults():
"""Monatskontingent ist die Voreinstellung, einen Übertrag gibt es nicht mehr."""
p = LicenseParams(license_type="trial")
assert p.credits_period == "monthly"
assert not hasattr(p, "credits_rollover")
assert p.budget_warning_percent == 80
def test_license_params_warnschwelle_null_ist_aus():
p = LicenseParams(license_type="trial", budget_warning_percent=0)
assert p.budget_warning_percent == 0
with pytest.raises(ValidationError):
LicenseParams(license_type="trial", budget_warning_percent=101)
def test_license_params_period_pattern():
LicenseParams(license_type="trial", credits_period="monthly")
LicenseParams(license_type="trial", credits_period="total")
with pytest.raises(ValidationError):
LicenseParams(license_type="trial", credits_period="weekly")
def test_license_create_inherits_credits_fields():
lic = LicenseCreate(
organization_id=1, license_type="annual",
credits_total=10000, credits_period="monthly",
)
assert lic.credits_total == 10000
assert lic.credits_period == "monthly"
def test_org_create_without_license_still_valid():
"""Rückwärtskompatibilität, das Lizenz-Objekt ist optional."""
org = OrgCreate(name="Test", slug="test")
assert org.license is None
def test_org_create_with_nested_license():
org = OrgCreate(
name="Test", slug="test",
license={"license_type": "trial", "credits_total": 10000},
)
assert org.license.credits_total == 10000
assert org.license.credits_period == "monthly"
with pytest.raises(ValidationError):
OrgCreate(name="Test", slug="test", license={"license_type": "trial", "credits_period": "weekly"})
def test_license_response_without_new_columns():
"""Responses müssen auch von einer noch nicht migrierten DB validieren."""
r = LicenseResponse(
id=1, organization_id=1, license_type="trial", max_users=5,
valid_from="2026-07-25", valid_until=None, status="active",
notes=None, created_at="2026-07-25",
)
assert r.credits_period == "monthly"
assert not hasattr(r, "credits_carried")
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")