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
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Tests for KnowledgeBase loader."""
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from src.knowledge_base.loader import KnowledgeBase
|
|
|
|
|
|
@pytest.fixture
|
|
def kb_dir(tmp_path) -> Path:
|
|
"""A temporary knowledge-base directory with a couple of markdown files."""
|
|
(tmp_path / "faq.md").write_text("# FAQ\nWann beginnt die Spielgruppe?\nIm August.")
|
|
(tmp_path / "fees.md").write_text("# Fees\nCHF 130 per month.")
|
|
return tmp_path
|
|
|
|
|
|
@pytest.fixture
|
|
def kb(kb_dir) -> KnowledgeBase:
|
|
return KnowledgeBase(kb_dir)
|
|
|
|
|
|
class TestKnowledgeBaseLoading:
|
|
def test_get_all_includes_file_content(self, kb):
|
|
content = kb.get_all()
|
|
assert "FAQ" in content
|
|
assert "Fees" in content
|
|
|
|
def test_get_all_concatenates_multiple_files(self, kb):
|
|
content = kb.get_all()
|
|
assert "CHF 130" in content
|
|
assert "Spielgruppe" in content
|
|
|
|
def test_reload_picks_up_new_file(self, kb, kb_dir):
|
|
(kb_dir / "schedule.md").write_text("# Schedule\nMonday 9:00")
|
|
kb.reload()
|
|
assert "Schedule" in kb.get_all()
|
|
|
|
def test_empty_directory_returns_empty_string(self, tmp_path):
|
|
kb = KnowledgeBase(tmp_path)
|
|
assert kb.get_all() == "" or isinstance(kb.get_all(), str)
|
|
|
|
def test_nonexistent_directory_does_not_raise_on_init(self, tmp_path):
|
|
# Should either handle gracefully or raise — just must not crash silently
|
|
missing = tmp_path / "does_not_exist"
|
|
try:
|
|
kb = KnowledgeBase(missing)
|
|
kb.get_all()
|
|
except (FileNotFoundError, OSError):
|
|
pass # Acceptable to raise on missing dir
|
|
|
|
def test_get_all_returns_string(self, kb):
|
|
assert isinstance(kb.get_all(), str)
|