def test_cross_sell_plugin_with_invalid_type(): plugin = ProductCrossSellsPlugin({"type": "foobar"}) assert plugin.config['type'] == ProductCrossSellType.RELATED plugin.config['type'] = 'foobar' context_data = plugin.get_context_data({'request': 'REQUEST'}) assert context_data['type'] == ProductCrossSellType.RELATED
def test_cross_sell_plugin_accepts_initial_config_as_string_or_enum(): plugin = ProductCrossSellsPlugin({"type": "computed"}) assert plugin.config["type"] == ProductCrossSellType.COMPUTED plugin = ProductCrossSellsPlugin( {"type": ProductCrossSellType.RECOMMENDED}) assert plugin.config["type"] == ProductCrossSellType.RECOMMENDED
def test_cross_sell_plugin_with_invalid_type(): plugin = ProductCrossSellsPlugin({"type": "foobar"}) assert plugin.config["type"] == ProductCrossSellType.RELATED plugin.config["type"] = "foobar" context_data = plugin.get_context_data({"request": "REQUEST"}) assert context_data["type"] == ProductCrossSellType.RELATED
def test_cross_sell_plugin_with_invalid_type(): plugin = ProductCrossSellsPlugin({"type": "foobar"}) assert plugin.config['type'] == ProductCrossSellType.RELATED plugin.config['type'] = 'foobar' context_data = plugin.get_context_data({'request': 'REQUEST'}) assert context_data['type'] == ProductCrossSellType.RELATED
def test_cross_sell_plugin_renders(): """ Test that the plugin renders a product """ shop = get_default_shop() supplier = get_default_supplier() product = create_product("test-sku", shop=shop, supplier=supplier, stock_behavior=StockBehavior.UNSTOCKED) computed = create_product("test-computed-sku", shop=shop, supplier=supplier, stock_behavior=StockBehavior.UNSTOCKED) type = ProductCrossSellType.COMPUTED ProductCrossSell.objects.create(product1=product, product2=computed, type=type) assert ProductCrossSell.objects.filter(product1=product, type=type).count() == 1 context = get_jinja_context(product=product) rendered = ProductCrossSellsPlugin({"type": type}).render(context) assert computed.sku in rendered