from pathlib import Path from app.sources.geizhals.result_parser import parse_result_html, with_page HTML = (Path(__file__).resolve().parents[2] / "fixtures" / "geizhals" / "nb-search-page.html").read_text( encoding="utf-8" ) def test_parser_reads_observed_gallery_cards() -> None: payload = parse_result_html(HTML, page_url="https://geizhals.de/?cat=nb") assert payload["blocked"] is False assert payload["page_count"] == 4 assert payload["result_count"] == 6431 assert [item["source_external_id"] for item in payload["items"]] == ["1000001", "1000002"] first = payload["items"][0] assert first["source_url"] == "https://geizhals.de/acme-notebook-14-a1000001.html" assert first["source_title"].startswith("Acme Notebook 14") assert first["manufacturer"] == "Acme" assert first["manufacturer_sku"] == "ACM-14-32" assert first["best_price"] == "1298.00" assert first["currency"] == "EUR" assert first["availability"] == "in_stock" assert first["seller_count"] == 8 assert first["raw_attributes"]["RAM"] == "32GB" assert first["raw_attributes"]["Betriebssystem"] == "Linux" assert first["normalized_attributes"]["ram_gb"] == 32 assert first["normalized_attributes"]["storage_gb"] == 1024 def test_challenge_html_is_not_turned_into_candidates() -> None: payload = parse_result_html( "Enable JavaScript and cookies to continue", page_url="https://geizhals.de/?cat=nb", ) assert payload["blocked"] is True assert payload["items"] == [] def test_with_page_uses_geizhals_pg_parameter() -> None: assert with_page("https://geizhals.de/?cat=nb&xf=17023_ab+16GB", 1) == "https://geizhals.de/?cat=nb&xf=17023_ab+16GB" assert "pg=3" in with_page("https://geizhals.de/?cat=nb&xf=17023_ab+16GB", 3)