def test_cross_sell_plugin_count(): shop = get_default_shop() product = create_product("test-sku", shop=shop, stock_behavior=StockBehavior.UNSTOCKED) context = get_jinja_context(product=product) total_count = 5 trim_count = 3 _create_cross_sell_products(product, shop, "related", total_count) assert ProductCrossSell.objects.filter(product1=product, type="related").count() == total_count assert len(list(product_helpers.get_product_cross_sells(context, product, type, trim_count))) == trim_count
def test_cross_sell_plugin_type(): """ Test that template helper returns correct number of cross sells when shop contains multiple relation types """ shop = get_default_shop() product = create_product("test-sku", shop=shop, stock_behavior=StockBehavior.UNSTOCKED) context = get_jinja_context(product=product) type_counts = (("related", 1), ("recommended", 2), ("computed", 3)) # Create cross sell products and relations in different quantities for type, count in type_counts: _create_cross_sell_products(product, shop, type, count) assert ProductCrossSell.objects.filter(product1=product, type=type).count() == count # Make sure quantites returned by plugin match for type, count in type_counts: assert len(list(product_helpers.get_product_cross_sells(context, product, type, count))) == count