Covers every module in src/ with unit tests:
- tests/conftest.py shared fixtures (complete_registration, fresh_state, …)
- tests/test_models.py RegistrationData.is_complete(), to_dict/from_dict round-trips
- tests/test_storage.py normalize_email, _diff_registrations, ConversationStore CRUD,
registration versioning
- tests/test_llm.py litellm wrapper — message construction, model passthrough,
error propagation
- tests/test_agent.py EmailAgent — new/existing conversations, registration
completion, admin notification, fallback on LLM error,
JSON parsing, _apply_updates
- tests/test_notifier.py AdminNotifier routing, fee calculation, SMTP dispatch
- tests/test_knowledge_base.py KnowledgeBase loading and reload
All external I/O (litellm, SMTP, filesystem) is mocked. Tests run fast (~6s)
with no network access required.
https://claude.ai/code/session_01HaUFs7SaLD5SoiuGCY27Tw
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""Shared pytest fixtures."""
|
|
|
|
import pytest
|
|
|
|
from src.models.conversation import ConversationState, ChatMessage
|
|
from src.models.registration import (
|
|
RegistrationData,
|
|
ChildInfo,
|
|
ParentGuardian,
|
|
EmergencyContact,
|
|
Booking,
|
|
BookingDay,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def complete_registration() -> RegistrationData:
|
|
"""A fully populated RegistrationData that passes is_complete()."""
|
|
return RegistrationData(
|
|
child=ChildInfo(
|
|
full_name="Lena Muster",
|
|
date_of_birth="2022-03-15",
|
|
special_needs="None",
|
|
),
|
|
parent_guardian=ParentGuardian(
|
|
full_name="Anna Muster",
|
|
street_address="Hauptstrasse 1",
|
|
postal_code="8117",
|
|
city="Fällanden",
|
|
phone="044 123 45 67",
|
|
email="anna.muster@example.com",
|
|
),
|
|
emergency_contact=EmergencyContact(
|
|
full_name="Hans Muster",
|
|
phone="079 123 45 67",
|
|
),
|
|
booking=Booking(
|
|
playgroup_types=["indoor"],
|
|
selected_days=[BookingDay(day="monday", type="indoor")],
|
|
),
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def fresh_state() -> ConversationState:
|
|
"""A brand-new ConversationState for a parent email."""
|
|
return ConversationState(
|
|
conversation_id="anna.muster@example.com",
|
|
parent_email="anna.muster@example.com",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def state_with_messages(fresh_state) -> ConversationState:
|
|
"""A ConversationState with a couple of chat turns."""
|
|
fresh_state.messages = [
|
|
ChatMessage(role="user", content="Hallo, ich möchte mein Kind anmelden."),
|
|
ChatMessage(role="assistant", content="Hallo! Wie heisst dein Kind?"),
|
|
ChatMessage(role="user", content="Lena Muster"),
|
|
]
|
|
return fresh_state
|