test: cover weekly official records import

This commit is contained in:
ik
2026-09-03 18:53:10 +07:00
parent fda2e5a7bc
commit b0974d5e4c
2 changed files with 37 additions and 1 deletions
+18 -1
View File
@@ -12,6 +12,7 @@ from app.models import CatchReport, ImportStatus, OfficialRecordImport, SourceTy
FIXTURE = Path(__file__).parents[3] / "tests" / "fixtures" / "records_ru_sample.html"
WEEKLY_FIXTURE = Path(__file__).parents[3] / "tests" / "fixtures" / "weekly_records_sample.html"
def test_parser_and_import_are_idempotent() -> None:
@@ -31,6 +32,22 @@ def test_parser_and_import_are_idempotent() -> None:
assert db.scalar(select(func.count()).select_from(OfficialRecordImport)) == 2
def test_manual_weekly_category_import_uses_its_own_identity() -> None:
html = WEEKLY_FIXTURE.read_text(encoding="utf-8")
engine = create_engine("sqlite://")
Base.metadata.create_all(engine)
with Session(engine) as db:
run = import_records(
db, url="fixture://weekly-records", region="RU",
category="weekly-ultralight", html=html,
)
report = db.scalar(select(CatchReport).where(CatchReport.source_type == SourceType.official_record))
assert (run.rows_seen, run.rows_created, run.rows_updated) == (1, 1, 0)
assert report.weight_g == 8_023
assert report.raw_payload["category"] == "weekly-ultralight"
assert report.raw_payload["fish"] == "Wochenfisch"
def test_failed_import_preserves_previous_records_and_is_logged() -> None:
html = FIXTURE.read_text(encoding="utf-8")
engine = create_engine("sqlite://")
@@ -53,7 +70,7 @@ def test_import_rejects_changed_column_contract() -> None:
html = FIXTURE.read_text(encoding="utf-8").replace(
'class="col data"', 'class="col changed"', 1
)
with pytest.raises(ImportSourceError, match="record columns changed"):
with pytest.raises(ImportSourceError, match="records columns changed"):
parse_html(html, region="RU", category="records")