mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
fix: Handle missing dimension108 in special attributes extraction (#706)
This commit is contained in:
@@ -466,7 +466,9 @@ class AdExtractor(WebScrapingMixin):
|
||||
"""
|
||||
|
||||
# e.g. "art_s:lautsprecher_kopfhoerer|condition_s:like_new|versand_s:t"
|
||||
special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"]["dimension108"]
|
||||
special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"].get("dimension108")
|
||||
if not special_attributes_str:
|
||||
return {}
|
||||
special_attributes = dict(item.split(":") for item in special_attributes_str.split("|") if ":" in item)
|
||||
special_attributes = {k: v for k, v in special_attributes.items() if not k.endswith(".versand_s") and k != "versand_s"}
|
||||
return special_attributes
|
||||
|
||||
@@ -754,6 +754,20 @@ class TestAdExtractorCategory:
|
||||
assert "art_s" in result
|
||||
assert result["art_s"] == "maedchen"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
# pylint: disable=protected-access
|
||||
async def test_extract_special_attributes_missing_dimension108(self, extractor:AdExtractor) -> None:
|
||||
"""Test extraction of special attributes when dimension108 key is missing."""
|
||||
belen_conf:dict[str, Any] = {
|
||||
"universalAnalyticsOpts": {
|
||||
"dimensions": {
|
||||
# dimension108 key is completely missing
|
||||
}
|
||||
}
|
||||
}
|
||||
result = await extractor._extract_special_attributes_from_ad_page(belen_conf)
|
||||
assert result == {}
|
||||
|
||||
|
||||
class TestAdExtractorContact:
|
||||
"""Tests for contact information extraction."""
|
||||
|
||||
Reference in New Issue
Block a user