BuyingAgent/backend/tests/unit/test_discovery_urlgen.py
Lars b276758ee1
All checks were successful
Deploy Development / deploy (push) Successful in 1m19s
Test Suite / pytest-backend (push) Successful in 31s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-checks (push) Successful in 28s
Stelle den Frontend-MVP und die v0.3-API auf develop bereit, damit Dev API und PWA zusammen deployen.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-04 13:04:59 +02:00

82 lines
2.4 KiB
Python

from app.discovery.mapping import verify_roundtrip
from app.discovery.urlgen import generate_search_url
CRITERIA = [
{"id": "ram", "criterion": "ram_gb", "operator": ">=", "value": 24, "mandatory": True},
{"id": "price", "criterion": "price_eur", "operator": "<=", "value": 2000, "mandatory": True},
{"id": "weight", "criterion": "weight_kg", "operator": "<=", "value": 1.6, "mandatory": True},
]
MAPPINGS = [
{
"criterion_key": "ram_gb",
"external_filter_key": "17023",
"source_value": "ab 24GB",
"encoding": {"url_param": "xf"},
"status": "VERIFIED",
},
{
"criterion_key": "price_eur",
"external_filter_key": "price",
"source_value": None,
"encoding": {"url_param": "maxp"},
"status": "VERIFIED",
},
]
def test_ram_and_price_url_is_reproducible():
first, internal = generate_search_url(
category_url="https://geizhals.de/?cat=nb",
criteria_items=CRITERIA,
mappings=MAPPINGS,
)
second, _ = generate_search_url(
category_url="https://geizhals.de/?cat=nb",
criteria_items=CRITERIA,
mappings=MAPPINGS,
)
assert first == second
assert "xf=17023_ab+24GB" in first
assert "maxp=2000" in first
assert internal == ["weight_kg"]
def test_internal_only_does_not_change_url():
without_weight, _ = generate_search_url(
category_url="https://geizhals.de/?cat=nb",
criteria_items=CRITERIA[:2],
mappings=MAPPINGS,
)
with_weight, internal = generate_search_url(
category_url="https://geizhals.de/?cat=nb",
criteria_items=CRITERIA,
mappings=MAPPINGS,
)
assert without_weight == with_weight
assert "weight_kg" in internal
def test_broken_mapping_is_not_used():
url, internal = generate_search_url(
category_url="https://geizhals.de/?cat=nb",
criteria_items=CRITERIA,
mappings=[{**MAPPINGS[0], "status": "BROKEN"}, MAPPINGS[1]],
)
assert "17023" not in url
assert "ram_gb" in internal
def test_roundtrip_verifies_xf_and_maxp():
assert verify_roundtrip(
category_url="https://geizhals.de/?cat=nb",
criterion=CRITERIA[0],
mapping=MAPPINGS[0],
)
assert verify_roundtrip(
category_url="https://geizhals.de/?cat=nb",
criterion=CRITERIA[1],
mapping=MAPPINGS[1],
)