gendesign/tradein-mvp/backend/tests/test_avito_address_clean.py
lekss361 9e1c7d5147 fix(tradein-avito): strip Emotion CSS from listings.address
Avito DOM leaks inline <style>.css-XXX{...}</style> inside the location <p>,
which gets pulled by .text(strip=True). Add _clean_address() helper that strips
CSS rules + post-address noise (Площадь N года, от N мин.), apply at extraction
site. Also applied to address_full in avito_detail.py via import from avito.py.
Backfill migration cleans the ~hundreds of historical rows.

Source: estimate a0a0b820-e8a8-4eee-aa73-0ab3b98ac233 analog #4.
2026-05-24 13:28:41 +03:00

24 lines
814 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from app.services.scrapers.avito import _clean_address
def test_strips_css_noise():
raw = (
"ул. Токарей, 56к1Площадь 1905 года.css-39hgr0{fill:currentColor;"
"height:1em;box-sizing:border-box;}.css-39hgr0:focus{outline:none;}"
"от 31 мин.Геологическая.css-39hgr0{...}"
)
assert _clean_address(raw) == "ул. Токарей, 56к1"
def test_clean_address_passthrough():
assert _clean_address("ул. Малышева, 1") == "ул. Малышева, 1"
def test_clean_handles_none():
assert _clean_address(None) is None
assert _clean_address("") is None
assert _clean_address(" ") is None
def test_clean_strips_trailing_punctuation():
assert _clean_address("ул. Ленина, 5,") == "ул. Ленина, 5"