@pytest.mark.django_db
def test_limited_methods():
 unique_shipping_method = get_shipping_method(name='unique', price=0)
 shop = get_default_shop()
 common_product = create_product(sku='SH_COMMON', shop=shop)
 unique_product = create_product(sku='SH_UNIQUE', shop=shop)
 unique_shop_product = unique_product.get_shop_instance(shop)
 unique_shop_product.limit_shipping_methods = True
 unique_shop_product.shipping_methods.add(unique_shipping_method)
 unique_shop_product.save()
 impossible_product = create_product(sku='SH_IMP', shop=shop)
 imp_shop_product = impossible_product.get_shop_instance(shop)
 imp_shop_product.limit_shipping_methods = True
 imp_shop_product.save()
 for (product_ids, method_ids) in [((common_product.pk, unique_product.pk), (unique_shipping_method.pk,)), ((common_product.pk,), ShippingMethod.objects.values_list('pk', flat=True)), ((unique_product.pk,), (unique_shipping_method.pk,)), ((unique_product.pk, impossible_product.pk), ()), ((common_product.pk, impossible_product.pk), ())]:
  product_ids = set(product_ids)
  assert (ShippingMethod.objects.available_ids(shop=shop, products=product_ids) == set(method_ids))

@ pytest . mark . django_db def test_limited_methods ( ) : unique_shipping_method = get_shipping_method ( name = 'unique' , price = 0 ) shop = get_default_shop ( ) common_product = create_product ( sku = 'SH_COMMON' , shop = shop ) unique_product = create_product ( sku = 'SH_UNIQUE' , shop = shop ) unique_shop_product = unique_product . get_shop_instance ( shop ) unique_shop_product . limit_shipping_methods = True unique_shop_product . shipping_methods . add ( unique_shipping_method ) unique_shop_product . save ( ) impossible_product = create_product ( sku = 'SH_IMP' , shop = shop ) imp_shop_product = impossible_product . get_shop_instance ( shop ) imp_shop_product . limit_shipping_methods = True imp_shop_product . save ( ) for ( product_ids , method_ids ) in [ ( ( common_product . pk , unique_product . pk ) , ( unique_shipping_method . pk , ) ) , ( ( common_product . pk , ) , ShippingMethod . objects . values_list ( 'pk' , flat = True ) ) , ( ( unique_product . pk , ) , ( unique_shipping_method . pk , ) ) , ( ( unique_product . pk , impossible_product . pk ) , ( ) ) , ( ( common_product . pk , impossible_product . pk ) , ( ) ) ] : product_ids = set ( product_ids ) assert ( ShippingMethod . objects . available_ids ( shop = shop , products = product_ids ) == set ( method_ids ) )
test that products can declare that they limit available shipping methods .