"""日报数据模型单元测试。""" from __future__ import annotations from datetime import date, datetime import pytest from pydantic import ValidationError from report_db.models import EventRow, ReportData class TestEventRow: def test_minimal(self) -> None: ev = EventRow(section="news", rank=1, title="标题") assert ev.importance is None assert ev.sentiment is None def test_full(self) -> None: ev = EventRow( section="intl", rank=2, importance=4, event_type="地缘政治", title="t", summary="s", sentiment="negative", source="ForexLive", url="https://x.com/1", ) assert ev.sentiment == "negative" def test_missing_title_raises(self) -> None: with pytest.raises(ValidationError): EventRow(section="news", rank=1) # type: ignore[call-arg] class TestReportData: def test_defaults(self) -> None: r = ReportData( report_date=date(2026, 7, 11), report_type="finance", generated_at=datetime(2026, 7, 11, 7, 0), ) assert r.file_name == "" assert r.stats == {} assert r.events == [] def test_with_events(self) -> None: r = ReportData( report_date=date(2026, 7, 11), report_type="finance", generated_at=datetime(2026, 7, 11, 7, 0), ai_summary="摘要", events=[EventRow(section="xwlb", rank=1, title="t")], ) assert len(r.events) == 1