diff --git a/apps/api/tests/test_importer.py b/apps/api/tests/test_importer.py index 2a19df0..34977be 100644 --- a/apps/api/tests/test_importer.py +++ b/apps/api/tests/test_importer.py @@ -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") diff --git a/tests/fixtures/weekly_records_sample.html b/tests/fixtures/weekly_records_sample.html new file mode 100644 index 0000000..89def05 --- /dev/null +++ b/tests/fixtures/weekly_records_sample.html @@ -0,0 +1,19 @@ + +
+ +