feat(admin): serverseitige Pydantic-Validatoren für Notfall-Profilfelder

Härtung zusätzlich zur Frontend-Prüfung: AdminUserPrefsUpdate validiert
nicht-leere Werte (leer/None = konform) und liefert sonst 422:
- postal_code: 5 Ziffern · phone_mobile/phone_landline: Telefonformat
- birth_date: TT.MM.JJJJ (echtes Datum) · emergency_contacts: CSV gültiger
  E-Mails · emergency_phones: CSV gültiger Nummern
Regeln spiegeln die Frontend-Validierung. 10 neue Tests (gültig/leer/ungültig),
Suite 250 grün.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-06-25 18:24:33 +02:00
commit 2c2231b684
2 changed files with 105 additions and 2 deletions

View file

@ -0,0 +1,36 @@
import pytest
from pydantic import ValidationError
from app.schemas import AdminUserPrefsUpdate
def test_valid_profile_passes():
AdminUserPrefsUpdate(
full_name="Frieda Schlüter", postal_code="50670",
phone_mobile="+4915127747511", phone_landline="040 123456",
birth_date="14.02.1976",
emergency_contacts="a@b.de, c@d.com",
emergency_phones="+4915127747511, 040 12345",
location_consent=True,
)
def test_empty_and_none_pass():
# Leere/None-Felder gelten als konform (optional).
AdminUserPrefsUpdate(postal_code="", phone_mobile="", birth_date="",
emergency_contacts="", emergency_phones=None)
@pytest.mark.parametrize("field,value", [
("postal_code", "123"),
("postal_code", "abcde"),
("phone_mobile", "hallo"),
("phone_landline", "xx"),
("birth_date", "1976-02-14"),
("birth_date", "31.02.2020"),
("emergency_contacts", "a@b.de, nope"),
("emergency_phones", "kein-telefon!!"),
])
def test_invalid_rejected(field, value):
with pytest.raises(ValidationError):
AdminUserPrefsUpdate(**{field: value})