"""Tests for data models.""" import pytest from datetime import datetime from src.models.verse import ( BookMetadata, ChapterSummary, GlossaryTerm, TranslationContext, TranslationOutput, Verse, VerseReference, ) class TestVerseReference: """Tests for VerseReference model.""" def test_create_verse_reference(self) -> None: """Test creating a verse reference.""" ref = VerseReference(book="john", chapter=1, verse=1) assert ref.book == "john" assert ref.chapter == 1 assert ref.verse == 1 def test_verse_reference_str(self) -> None: """Test string representation.""" ref = VerseReference(book="john", chapter=3, verse=16) assert str(ref) == "john:3:16" def test_verse_reference_from_string(self) -> None: """Test parsing from string.""" ref = VerseReference.from_string("john:1:1") assert ref.book == "john" assert ref.chapter == 1 assert ref.verse == 1 def test_verse_reference_from_string_uppercase(self) -> None: """Test parsing handles case insensitivity.""" ref = VerseReference.from_string("JOHN:1:1") assert ref.book == "john" def test_verse_reference_invalid_format(self) -> None: """Test parsing invalid format raises error.""" with pytest.raises(ValueError, match="Invalid verse reference"): VerseReference.from_string("john:1") def test_verse_reference_invalid_format_too_many_parts(self) -> None: """Test parsing invalid format with too many parts.""" with pytest.raises(ValueError, match="Invalid verse reference"): VerseReference.from_string("john:1:1:extra") class TestVerse: """Tests for Verse model.""" def test_create_verse(self) -> None: """Test creating a verse.""" ref = VerseReference(book="john", chapter=1, verse=1) verse = Verse(reference=ref, greek_text="Ἐν ἀρχῇ") assert verse.reference == ref assert verse.greek_text == "Ἐν ἀρχῇ" def test_verse_has_source_text_with_greek(self) -> None: """Test has_source_text with Greek text.""" ref = VerseReference(book="john", chapter=1, verse=1) verse = Verse(reference=ref, greek_text="Ἐν ἀρχῇ") assert verse.has_source_text() is True def test_verse_has_source_text_with_hebrew(self) -> None: """Test has_source_text with Hebrew text.""" ref = VerseReference(book="genesis", chapter=1, verse=1) verse = Verse(reference=ref, hebrew_text="בְּרֵאשִׁית") assert verse.has_source_text() is True def test_verse_has_source_text_empty(self) -> None: """Test has_source_text with no source text.""" ref = VerseReference(book="john", chapter=1, verse=1) verse = Verse(reference=ref, english_kjv="In the beginning") assert verse.has_source_text() is False class TestGlossaryTerm: """Tests for GlossaryTerm model.""" def test_create_glossary_term(self) -> None: """Test creating a glossary term.""" term = GlossaryTerm( original="λόγος", transliteration="logos", japanese="言葉", english="word", notes="Used in John 1:1", ) assert term.original == "λόγος" assert term.transliteration == "logos" assert term.japanese == "言葉" assert term.english == "word" assert term.notes == "Used in John 1:1" def test_create_glossary_term_without_notes(self) -> None: """Test creating a glossary term without notes.""" term = GlossaryTerm( original="ἀγάπη", transliteration="agape", japanese="愛", english="love", ) assert term.notes is None class TestBookMetadata: """Tests for BookMetadata model.""" def test_create_book_metadata(self) -> None: """Test creating book metadata.""" meta = BookMetadata( book="john", name_japanese="ヨハネによる福音書", name_english="Gospel of John", testament="NT", author="John the Apostle", themes=["love", "light", "life"], description="The fourth Gospel", chapter_count=21, verse_count=879, ) assert meta.book == "john" assert meta.name_japanese == "ヨハネによる福音書" assert len(meta.themes) == 3 class TestChapterSummary: """Tests for ChapterSummary model.""" def test_create_chapter_summary(self) -> None: """Test creating chapter summary.""" summary = ChapterSummary( book="john", chapter=1, summary="The prologue introduces Jesus as the Word.", key_events=["Word becomes flesh"], key_characters=["Jesus", "John the Baptist"], key_themes=["Light", "Word"], ) assert summary.book == "john" assert summary.chapter == 1 class TestTranslationContext: """Tests for TranslationContext model.""" def test_create_translation_context(self) -> None: """Test creating translation context.""" ref = VerseReference(book="john", chapter=1, verse=1) verse = Verse(reference=ref, greek_text="Ἐν ἀρχῇ") context = TranslationContext(target_verse=verse) assert context.target_verse == verse assert context.preceding_verses == [] assert context.following_verses == [] class TestTranslationOutput: """Tests for TranslationOutput model.""" def test_create_translation_output(self) -> None: """Test creating translation output.""" ref = VerseReference(book="john", chapter=1, verse=1) output = TranslationOutput( reference=ref, text="初めに言葉があった。", model="claude-sonnet-4-20250514", ) assert output.reference == ref assert output.text == "初めに言葉があった。" assert output.model == "claude-sonnet-4-20250514" assert output.prompt_version == "v1.0" def test_translation_output_with_timestamp(self) -> None: """Test translation output has timestamp.""" ref = VerseReference(book="john", chapter=1, verse=1) output = TranslationOutput( reference=ref, text="初めに言葉があった。", model="claude-sonnet-4-20250514", ) assert isinstance(output.timestamp, datetime)