Пример #1
0
def test_cross_sell_plugin_with_invalid_type_2(rf):
    plugin = ProductCrossSellsPlugin({"type": None})
    assert plugin.config['type'] == None

    context = get_context(rf)
    context_data = plugin.get_context_data({'request': context["request"]})
    assert context_data['data_url'] == "/"
Пример #2
0
def test_cross_sell_plugin_renders(rf, reindex_catalog):
    """
    Test that the plugin renders a product
    """
    shop = get_default_shop()
    supplier = get_default_supplier()
    product = create_product("test-sku", shop=shop, supplier=supplier)
    computed = create_product("test-computed-sku",
                              shop=shop,
                              supplier=supplier)
    reindex_catalog()

    type = ProductCrossSellType.COMPUTED

    ProductCrossSell.objects.create(product1=product,
                                    product2=computed,
                                    type=type)
    assert ProductCrossSell.objects.filter(product1=product,
                                           type=type).count() == 1

    context = get_context(rf, product=product)
    rendered = ProductCrossSellsPlugin({"type": type}).render(context)
    assert computed.sku in rendered

    plugin = ProductCrossSellsPlugin({"type": type, "cache_timeout": 120})
    plugin_context = plugin.get_context_data(get_context(rf, product=product))
    context_data_url = plugin_context["data_url"]
    check_expected_product_count(context_data_url, 1)
    check_expected_product_count(context_data_url,
                                 1)  # one for checking it is cached
Пример #3
0
def test_cross_sell_plugin_with_product_that_does_not_exists(rf):
    plugin = ProductCrossSellsPlugin({"type": None})
    assert plugin.config['type'] == None

    context = get_context(rf)
    plugin.config["product"] = "1111"
    context_data = plugin.get_context_data({'request': context["request"]})
    assert context_data['data_url'] == "/"
Пример #4
0
def test_cross_sell_plugin_with_invalid_type(rf):
    plugin = ProductCrossSellsPlugin({"type": "foobar"})
    assert plugin.config['type'] == ProductCrossSellType.RELATED

    context = get_context(rf)
    plugin.config['type'] = 'foobar'
    context_data = plugin.get_context_data({'request': context["request"]})
    assert context_data['data_url'] == "/"