Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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"])
Exemplo n.º 3
0
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"]
Exemplo n.º 4
0
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"])