BuyingAgent/backend/tests/unit/test_geizhals_taxonomy_api.py

48 lines
1.9 KiB
Python
Raw Permalink Normal View History

from app.sources.geizhals.taxonomy_api import categorylist_api_url, parse_taxonomy_api
def test_categorylist_api_url_keeps_category_and_market() -> None:
url = categorylist_api_url("https://geizhals.de/?cat=gra16_512&hloc=at")
assert "cat=gra16_512" in url
assert "hloc=at" in url
assert "filters_only=1" in url
def test_api_payload_keeps_enum_list_and_groups() -> None:
payload = parse_taxonomy_api(
{
"response": {
"filters": [
{
"id": "525",
"title": "Hersteller",
"type": "enum",
"values": [
{"id": "525_Apple", "name": "Apple"},
{"id": "525_Lenovo", "name": "Lenovo"},
],
},
{
"id": "2379",
"title": "Display-Größe ab",
"type": "range_from",
"values": [{"id": "2379_13", "name": "ab 13\""}],
},
]
}
},
category_ref="nb",
source_url="https://geizhals.de/?cat=nb",
)
keys = {item["external_filter_key"] for item in payload["filters"]}
assert {"525", "2379", "price"} <= keys
hersteller = next(item for item in payload["filters"] if item["external_filter_key"] == "525")
assert hersteller["filter_type"] == "ENUM"
assert hersteller["group_label"] == "Allgemein"
assert {option["source_value"] for option in hersteller["options"]} == {"Apple", "Lenovo"}
assert hersteller["encoding"]["options"]["Apple"] == "Apple"
display = next(item for item in payload["filters"] if item["external_filter_key"] == "2379")
assert display["group_label"] == "Display"
assert display["filter_type"] == "NUMERIC_THRESHOLD"
assert display["options"][0]["operator"] == ">="