58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from src.models.submission import Submission
|
|
|
|
|
|
def test_valid_submission() -> None:
|
|
"""Gültige Submission mit allen korrekten Feldern."""
|
|
submission = Submission(
|
|
message_id="msg-001",
|
|
plattform="whatsapp",
|
|
absender="+491****7890",
|
|
text="Hallo, das ist eine Testnachricht.",
|
|
)
|
|
assert submission.message_id == "msg-001"
|
|
assert submission.plattform == "whatsapp"
|
|
assert submission.absender == "+491****7890"
|
|
assert submission.text == "Hallo, das ist eine Testnachricht."
|
|
assert isinstance(submission.zeitstempel, datetime)
|
|
assert submission.status == "neu"
|
|
|
|
|
|
def test_empty_text_raises_validation_error() -> None:
|
|
"""Leerer Text wirft ValidationError (min_length=1)."""
|
|
with pytest.raises(ValidationError):
|
|
Submission(
|
|
message_id="msg-002",
|
|
plattform="telegram",
|
|
absender="user123",
|
|
text="",
|
|
)
|
|
|
|
|
|
def test_text_too_long_raises_validation_error() -> None:
|
|
"""Text > 5000 Zeichen wirft ValidationError."""
|
|
long_text = "x" * 5001
|
|
with pytest.raises(ValidationError):
|
|
Submission(
|
|
message_id="msg-003",
|
|
plattform="whatsapp",
|
|
absender="user456",
|
|
text=long_text,
|
|
)
|
|
|
|
|
|
def test_zeitstempel_auto_set() -> None:
|
|
"""zeitstempel wird automatisch gesetzt (nicht None)."""
|
|
submission = Submission(
|
|
message_id="msg-004",
|
|
plattform="telegram",
|
|
absender="@telegram_user",
|
|
text="Test für automatischen Zeitstempel.",
|
|
)
|
|
assert submission.zeitstempel is not None
|
|
assert isinstance(submission.zeitstempel, datetime)
|