""" Core logic tests for Scenar Creator v3. Tests models, validation, and document structure. """ import pytest from pydantic import ValidationError as PydanticValidationError from app.models.event import Block, ProgramType, EventInfo, ScenarioDocument from app.core.validator import ScenarsError, ValidationError # --- Model tests --- def test_block_default_id(): b = Block(date="2026-03-01", start="09:00", end="10:00", title="Test", type_id="ws") assert b.id is not None assert len(b.id) > 0 def test_block_optional_fields(): b = Block(date="2026-03-01", start="09:00", end="10:00", title="Test", type_id="ws") assert b.responsible is None assert b.notes is None assert b.series_id is None def test_block_series_id(): b = Block(date="2026-03-01", start="09:00", end="10:00", title="Test", type_id="ws", series_id="s_abc123") assert b.series_id == "s_abc123" def test_block_with_all_fields(): b = Block( id="custom-id", date="2026-03-01", start="09:00", end="10:00", title="Full Block", type_id="ws", responsible="John", notes="A note" ) assert b.id == "custom-id" assert b.responsible == "John" assert b.notes == "A note" def test_program_type(): pt = ProgramType(id="main", name="Main Program", color="#3B82F6") assert pt.id == "main" assert pt.name == "Main Program" assert pt.color == "#3B82F6" def test_event_info_minimal(): e = EventInfo(title="Test") assert e.title == "Test" assert e.subtitle is None assert e.date is None assert e.location is None def test_event_info_full(): e = EventInfo(title="Event", subtitle="Sub", date="2026-03-01", location="Prague") assert e.location == "Prague" def test_scenario_document(): doc = ScenarioDocument( event=EventInfo(title="Test"), program_types=[ProgramType(id="ws", name="Workshop", color="#FF0000")], blocks=[Block(date="2026-03-01", start="09:00", end="10:00", title="B1", type_id="ws")] ) assert doc.version == "1.0" assert len(doc.blocks) == 1 assert len(doc.program_types) == 1 def test_scenario_document_serialization(): doc = ScenarioDocument( event=EventInfo(title="Test"), program_types=[ProgramType(id="ws", name="Workshop", color="#FF0000")], blocks=[Block(id="b1", date="2026-03-01", start="09:00", end="10:00", title="B1", type_id="ws")] ) data = doc.model_dump(mode="json") assert data["event"]["title"] == "Test" assert data["blocks"][0]["type_id"] == "ws" assert data["blocks"][0]["id"] == "b1" def test_scenario_document_missing_title(): with pytest.raises(PydanticValidationError): ScenarioDocument( event=EventInfo(), program_types=[], blocks=[] ) # --- Validator tests --- def test_scenars_error_hierarchy(): assert issubclass(ValidationError, ScenarsError) def test_validation_error_message(): err = ValidationError("test error") assert str(err) == "test error"