add mobilede tests

This commit is contained in:
qananasikq
2026-04-29 19:13:18 +03:00
parent f00819a21c
commit 8f94828b29
11 changed files with 221 additions and 119 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
import json
from iaai_scraper.browser.fast_client import (
from mobilede_scraper.browser.fast_client import (
DETAIL_MARKER,
LISTING_MARKER,
build_resizer_images_from_keys,
@@ -10,7 +10,7 @@ from iaai_scraper.browser.fast_client import (
parse_listing_page,
parse_product_details_vm,
)
from iaai_scraper.parsing.fast_mapper import FastCarMapper
from mobilede_scraper.parsing.fast_mapper import FastCarMapper
def test_parse_listing_page_extracts_hidden_payloads() -> None:
@@ -78,10 +78,10 @@ def test_parse_product_details_vm_and_map_record() -> None:
parsed = parse_product_details_vm(html)
record = FastCarMapper().map_payload_to_record(
detail_payload=parsed,
vehicle_url="https://www.iaai.com/VehicleDetail/45078011~US",
vehicle_url="https://www.MOBILEDE.com/VehicleDetail/45078011~US",
)
assert record.origin_id == "iaai:45078011~US"
assert record.origin_id == "mobilede:45078011"
assert record.brand == "ACURA"
assert record.model == "RSX BASE"
assert record.year == 2002
@@ -94,6 +94,51 @@ def test_parse_product_details_vm_and_map_record() -> None:
assert len(record.images) == 1
def test_fast_mapper_uses_fallback_keys_and_normalization() -> None:
payload = {
"inventoryView": {
"attributes": {
"Id": "454502861",
"FirstRegistration": "05/2012",
"Make": "BMW",
"Model": "X1",
"Variant": "xDrive 20d",
"Currency": "EUR",
"Mileage": "50.100 km",
"ColorDesc": "silber metallic",
"Category": "Kombi",
"TransmissionType": "Schaltgetriebe",
"EngineInformation": "1995 ccm, Diesel",
},
"imageDimensions": {
"keys": {
"$values": [
{"k": "454502861~I1", "w": 1600, "h": 1200, "i": 0},
]
}
},
},
"auctionInformation": {
"biddingInformation": {"buyNowPrice": "9.900 €"},
},
}
record = FastCarMapper().map_payload_to_record(
detail_payload=payload,
vehicle_url="https://www.mobile.de/ru/транспортные-средства/подробности.html?id=454502861&vc=Car&s=Car",
)
assert record.model == "X1 xDrive 20d"
assert record.year == 2012
assert record.price == 9900
assert record.mileage == 50100
assert record.color == "silver"
assert record.drive == "4WD"
assert record.gearbox == "MT"
assert record.body_type == "STATION_WAGON"
assert record.engine_volume == 1995
def test_build_resizer_images_from_keys_deduplicates_and_orders() -> None:
keys = [
{"k": "abc~1", "w": 2000, "h": 1500, "i": 2},