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'] == "/"
def get_product_cross_sell_highlight(request, product_id, relation_type, use_parents, count, cache_timeout): key, html = context_cache.get_cached_value( identifier="xtheme_product_cross_sell_highlight", item=PRODUCT_HIGHLIGHT_CACHE_KEY_PREFIX % {"shop_id": request.shop.pk}, context=request, product_id=product_id, type=relation_type, use_variation_parents=use_parents, count=count, cache_timeout=cache_timeout, ) if html is not None: return HttpResponse(html) plugin = ProductCrossSellsPlugin( config={ "product": int(product_id), "type": relation_type, "use_variation_parents": bool(use_parents), "count": int(count), "cache_timeout": int(cache_timeout), }) html = plugin.render(dict(request=request)) context_cache.set_cached_value(key, html, int(cache_timeout)) return HttpResponse(html)
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_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
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'] == "/"
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'] == "/"