Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Review changes

Michał Sipac2eaa572afc5
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.py
index 34e814b7a1..d975d6c19b 100644
--- a/saleor/graphql/checkout/tests/test_checkout.py
+++ b/saleor/graphql/checkout/tests/test_checkout.py
@@ -560,12 +560,13 @@ def test_checkout_create_check_lines_quantity_different_shipping_zone_insufficie
variant_with_many_stocks_different_shipping_zones,
graphql_address_data,
):
+ """Check if insufficient stock exception will be raised.
+ If item from checkout will not have enough quantity in correct shipping zone for
+ shipping address INSUFICIENT_STOCK checkout error should be raised."""
variant = variant_with_many_stocks_different_shipping_zones
- stock = Stock.objects.filter(
+ Stock.objects.filter(
warehouse__shipping_zones__countries__contains="US", product_variant=variant
- ).first()
- stock.quantity = 0
- stock.save()
+ ).update(quantity=0)
variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)
test_email = "[email protected]"
shipping_address = graphql_address_data
@@ -1402,11 +1403,9 @@ def test_checkout_shipping_address_update_insufficient_stocks(
checkout = Checkout.objects.create()
checkout.set_country("PL", commit=True)
add_variant_to_checkout(checkout, variant, 1)
- stock = Stock.objects.filter(
+ Stock.objects.filter(
warehouse__shipping_zones__countries__contains="US", product_variant=variant
- ).first()
- stock.quantity = 0
- stock.save()
+ ).update(quantity=0)
assert checkout.shipping_address is None
checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index e22c0606e0..4952338a8d 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -497,7 +497,12 @@ def shipping_zone(db): # pylint: disable=W0613
@pytest.fixture
def shipping_zones(db):
- shipping_zone_poland = ShippingZone.objects.create(name="Poland", countries=["PL"])
+ shipping_zone_poland, shipping_zone_usa = ShippingZone.objects.bulk_create(
+ [
+ ShippingZone(name="Poland", countries=["PL"]),
+ ShippingZone(name="USA", countries=["US"]),
+ ]
+ )
shipping_zone_poland.shipping_methods.create(
name="DHL",
minimum_order_price=Money(0, "USD"),
@@ -505,7 +510,6 @@ def shipping_zones(db):
price=Money(10, "USD"),
shipping_zone=shipping_zone,
)
- shipping_zone_usa = ShippingZone.objects.create(name="USA", countries=["US"])
shipping_zone_usa.shipping_methods.create(
name="DHL",
minimum_order_price=Money(0, "USD"),
@@ -875,8 +879,12 @@ def variant(product) -> ProductVariant:
@pytest.fixture
def variant_with_many_stocks(variant, warehouses_with_shipping_zone):
warehouses = warehouses_with_shipping_zone
- Stock.objects.create(warehouse=warehouses[0], product_variant=variant, quantity=4)
- Stock.objects.create(warehouse=warehouses[1], product_variant=variant, quantity=3)
+ Stock.objects.bulk_create(
+ [
+ Stock(warehouse=warehouses[0], product_variant=variant, quantity=4),
+ Stock(warehouse=warehouses[1], product_variant=variant, quantity=3),
+ ]
+ )
return variant
@@ -885,8 +893,12 @@ def variant_with_many_stocks_different_shipping_zones(
variant, warehouses_with_different_shipping_zone
):
warehouses = warehouses_with_different_shipping_zone
- Stock.objects.create(warehouse=warehouses[0], product_variant=variant, quantity=4)
- Stock.objects.create(warehouse=warehouses[1], product_variant=variant, quantity=3)
+ Stock.objects.bulk_create(
+ [
+ Stock(warehouse=warehouses[0], product_variant=variant, quantity=4),
+ Stock(warehouse=warehouses[1], product_variant=variant, quantity=3),
+ ]
+ )
return variant