feat: implement data layer with comprehensive test infrastructure
- Define SQLModel schemas for Session, Note, and Link entities - Add API request/response models for RPC endpoints - Create LLM structured output models for Zettel extraction - Set up async database initialization with SQLModel and aiosqlite - Implement repository pattern for CRUD operations - Add complete test suite with pytest configuration - Create validation test runner for development workflow - Add .gitignore for Python/FastAPI project security
This commit is contained in:
131
tests/test_models.py
Normal file
131
tests/test_models.py
Normal file
@@ -0,0 +1,131 @@
|
||||
"""Test data models and validation."""
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.data.models import (
|
||||
StartSessionRequest,
|
||||
SendMessageRequest,
|
||||
SessionResponse,
|
||||
SessionStatusResponse,
|
||||
RawZettel,
|
||||
SegmentationResult,
|
||||
RawLink,
|
||||
LinkingResult,
|
||||
Note,
|
||||
Session,
|
||||
Link
|
||||
)
|
||||
|
||||
|
||||
class TestAPIModels:
|
||||
"""Test API request/response models."""
|
||||
|
||||
def test_start_session_request(self):
|
||||
"""Test StartSessionRequest validation."""
|
||||
req = StartSessionRequest(topic="AI Ethics")
|
||||
assert req.topic == "AI Ethics"
|
||||
|
||||
# Test empty topic fails
|
||||
with pytest.raises(ValidationError):
|
||||
StartSessionRequest(topic="")
|
||||
|
||||
def test_send_message_request(self):
|
||||
"""Test SendMessageRequest validation."""
|
||||
session_id = uuid.uuid4()
|
||||
req = SendMessageRequest(session_id=session_id, message="Hello")
|
||||
assert req.session_id == session_id
|
||||
assert req.message == "Hello"
|
||||
|
||||
# Test invalid UUID fails
|
||||
with pytest.raises(ValidationError):
|
||||
SendMessageRequest(session_id="invalid", message="Hello")
|
||||
|
||||
def test_session_response(self):
|
||||
"""Test SessionResponse model."""
|
||||
session_id = uuid.uuid4()
|
||||
resp = SessionResponse(
|
||||
session_id=session_id,
|
||||
status="active",
|
||||
message="Welcome!"
|
||||
)
|
||||
assert resp.session_id == session_id
|
||||
assert resp.status == "active"
|
||||
assert resp.message == "Welcome!"
|
||||
|
||||
|
||||
class TestLLMModels:
|
||||
"""Test LLM structured output models."""
|
||||
|
||||
def test_raw_zettel(self):
|
||||
"""Test RawZettel model."""
|
||||
zettel = RawZettel(
|
||||
title="Test Concept",
|
||||
content="This is a test concept about AI.",
|
||||
tags=["ai", "test", "concept"]
|
||||
)
|
||||
assert zettel.title == "Test Concept"
|
||||
assert len(zettel.tags) == 3
|
||||
assert "ai" in zettel.tags
|
||||
|
||||
def test_segmentation_result(self):
|
||||
"""Test SegmentationResult model."""
|
||||
zettels = [
|
||||
RawZettel(title="Concept 1", content="Content 1", tags=["tag1"]),
|
||||
RawZettel(title="Concept 2", content="Content 2", tags=["tag2"])
|
||||
]
|
||||
result = SegmentationResult(notes=zettels)
|
||||
assert len(result.notes) == 2
|
||||
assert result.notes[0].title == "Concept 1"
|
||||
|
||||
def test_raw_link(self):
|
||||
"""Test RawLink model."""
|
||||
link = RawLink(
|
||||
target_note_id=str(uuid.uuid4()),
|
||||
relationship_context="Related through shared AI concepts"
|
||||
)
|
||||
assert uuid.UUID(link.target_note_id) # Should not raise
|
||||
assert "AI" in link.relationship_context
|
||||
|
||||
|
||||
class TestDatabaseModels:
|
||||
"""Test database models."""
|
||||
|
||||
def test_session_creation(self):
|
||||
"""Test Session model creation."""
|
||||
session = Session()
|
||||
assert isinstance(session.id, uuid.UUID)
|
||||
assert session.status == "active"
|
||||
assert session.transcript == []
|
||||
assert isinstance(session.created_at, datetime)
|
||||
|
||||
def test_note_creation(self):
|
||||
"""Test Note model creation."""
|
||||
session_id = uuid.uuid4()
|
||||
note = Note(
|
||||
title="Test Note",
|
||||
content="This is test content",
|
||||
tags=["test", "note"],
|
||||
session_id=session_id
|
||||
)
|
||||
assert isinstance(note.id, uuid.UUID)
|
||||
assert note.title == "Test Note"
|
||||
assert note.content == "This is test content"
|
||||
assert note.tags == ["test", "note"]
|
||||
assert note.session_id == session_id
|
||||
assert isinstance(note.created_at, datetime)
|
||||
|
||||
def test_link_creation(self):
|
||||
"""Test Link model creation."""
|
||||
source_id = uuid.uuid4()
|
||||
target_id = uuid.uuid4()
|
||||
link = Link(
|
||||
context="These concepts are related through...",
|
||||
source_id=source_id,
|
||||
target_id=target_id
|
||||
)
|
||||
assert link.context == "These concepts are related through..."
|
||||
assert link.source_id == source_id
|
||||
assert link.target_id == target_id
|
||||
Reference in New Issue
Block a user