def test_item_merge_into_list_processor_wrong_field_exception(): test_item = {"category": "electronics", "subcategory": "phones"} with pytest.raises(KeyError): processors.ItemKeysMergeIntoListProcessor( new_item_key="breadcrumbs", item_keys=["category", "subcategory", "type"]).parse(test_item)
def test_item_merge_into_list_processor(): test_item = {"category": "electronics", "subcategory": "phones"} item = processors.ItemKeysMergeIntoListProcessor( new_item_key="breadcrumbs", item_keys=["category", "subcategory"]).parse(test_item) assert item["breadcrumbs"] == ["electronics", "phones"] # test that old parsers have been removed assert all(k not in item for k in ["category", "subcategory"])
def test_item_merge_into_list_processor_ignore_none(): test_item = { "category": "electronics", "subcategory": "phones", "type": None } item = processors.ItemKeysMergeIntoListProcessor( new_item_key="breadcrumbs", item_keys=["category", "subcategory", "type"]).parse(test_item) assert item["breadcrumbs"] == ["electronics", "phones"]
def test_item_merge_into_list_processor_preserve_original(): test_item = {"category": "electronics", "subcategory": "phones"} item = processors.ItemKeysMergeIntoListProcessor( new_item_key="breadcrumbs", item_keys=["category", "subcategory"], preserve_original=True, ).parse(test_item) assert item["breadcrumbs"] == ["electronics", "phones"] # test that old parsers remain assert all(k in item for k in ["category", "subcategory"])