test: cover weekly official records import
This commit is contained in:
@@ -12,6 +12,7 @@ from app.models import CatchReport, ImportStatus, OfficialRecordImport, SourceTy
|
|||||||
|
|
||||||
|
|
||||||
FIXTURE = Path(__file__).parents[3] / "tests" / "fixtures" / "records_ru_sample.html"
|
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:
|
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
|
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:
|
def test_failed_import_preserves_previous_records_and_is_logged() -> None:
|
||||||
html = FIXTURE.read_text(encoding="utf-8")
|
html = FIXTURE.read_text(encoding="utf-8")
|
||||||
engine = create_engine("sqlite://")
|
engine = create_engine("sqlite://")
|
||||||
@@ -53,7 +70,7 @@ def test_import_rejects_changed_column_contract() -> None:
|
|||||||
html = FIXTURE.read_text(encoding="utf-8").replace(
|
html = FIXTURE.read_text(encoding="utf-8").replace(
|
||||||
'class="col data"', 'class="col changed"', 1
|
'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")
|
parse_html(html, region="RU", category="records")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="de"><body>
|
||||||
|
<!-- Reduced, anonymized fixture for one weekly-record category. -->
|
||||||
|
<div class="records flex_table">
|
||||||
|
<div class="row header">
|
||||||
|
<div class="col fish">Fisch</div><div class="col weight">Gewicht</div>
|
||||||
|
<div class="col location">Gewässer</div><div class="col bait">Köder</div>
|
||||||
|
<div class="col gamername">Spieler</div><div class="col data">Datum</div>
|
||||||
|
</div>
|
||||||
|
<div class="rows"><div class="row"><div class="records_subtable flex_table">
|
||||||
|
<div class="row header">
|
||||||
|
<div class="col fish"><div class="text">Wochenfisch</div></div>
|
||||||
|
<div class="col weight">8.023 kg</div><div class="col location">Wochengewässer</div>
|
||||||
|
<div class="col bait"><div class="bait_icon" title="Wochenköder"></div></div>
|
||||||
|
<div class="col gamername">Spieler Woche</div><div class="col data">01.09.26</div>
|
||||||
|
</div>
|
||||||
|
</div></div></div>
|
||||||
|
</div>
|
||||||
|
</body></html>
|
||||||
Reference in New Issue
Block a user