Exemple #1
0
def test_item_discount_processor_remove_item_sale_price_key():
    test_item = {"price": 29.99, "sale_price": 21.99}

    item = processors.ItemDiscountProcessor(
        remove_item_sale_price_key=True).parse(test_item)

    assert item == {"price": 29.99, "discount": 26.68}
Exemple #2
0
def test_item_discount_processor_decimals(price, sale_price, decimals, result):

    test_item = {"price": price, "sale_price": sale_price}

    item = processors.ItemDiscountProcessor(decimals=decimals).parse(test_item)

    assert item["discount"] == result
Exemple #3
0
def test_item_discount_processor_no_decimals_config():
    test_item = {"price": 29.99, "sale_price": 21.99}

    discount_processor = processors.ItemDiscountProcessor()
    discount_processor.init_config({"ED_ITEM_DISCOUNT_NO_DECIMALS": True})

    item = discount_processor.parse(test_item)

    assert item["discount"] == 27
Exemple #4
0
def test_item_discount_processor_remove_item_sale_price_key_config():
    test_item = {"price": 29.99, "sale_price": 21.99}

    discount_processor = processors.ItemDiscountProcessor()

    custom_config = {"ED_ITEM_DISCOUNT_REMOVE_ITEM_SALE_PRICE_KEY": True}
    discount_processor.init_config(custom_config)

    item = discount_processor.parse(test_item)

    assert item == {"price": 29.99, "discount": 26.68}
Exemple #5
0
def test_item_discount_processor_custom_keys():
    test_item = {"old_price": "29.99", "price": 22}

    item = processors.ItemDiscountProcessor(
        item_price_key="old_price",
        item_sale_price_key="price",
        item_discount_key="pdiscount",
    ).parse(test_item)

    expected_result = {"old_price": "29.99", "price": 22, "pdiscount": 26.64}
    assert item == expected_result
Exemple #6
0
def test_item_discount_processor_custom_keys_config():
    test_item = {"old_price": "29.99", "price": 22}

    # Test config setting
    config_params = {
        "ED_ITEM_DISCOUNT_ITEM_PRICE_KEY": "old_price",
        "ED_ITEM_DISCOUNT_ITEM_SALE_PRICE_KEY": "price",
        "ED_ITEM_DISCOUNT_ITEM_DISCOUNT_KEY": "pdiscount",
    }

    discount_processor = processors.ItemDiscountProcessor()
    discount_processor.init_config(config_params)

    item = discount_processor.parse(test_item)

    expected_result = {"old_price": "29.99", "price": 22, "pdiscount": 26.64}
    assert item == expected_result
Exemple #7
0
def test_item_discount_processor_no_decimals():
    test_item = {"price": 29.99, "sale_price": 21.99}

    item = processors.ItemDiscountProcessor(no_decimals=True).parse(test_item)

    assert item["discount"] == 27