Skip to content

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

Add benchmark for order fulfill mutation and additional test for fulfilling with gift cards

IKarbowiak52829a2f3ed7
diff --git a/saleor/giftcard/tests/test_utils.py b/saleor/giftcard/tests/test_utils.py
index 1c720fbb7a..04ed204fb7 100644
--- a/saleor/giftcard/tests/test_utils.py
+++ b/saleor/giftcard/tests/test_utils.py
@@ -233,3 +233,33 @@ def test_gift_cards_create(
send_notification_mock.assert_called_once_with(
staff_user, None, user_email, non_shippable_gift_card, manager
)
+
+
+@patch("saleor.giftcard.utils.send_gift_card_notification")
+def test_gift_cards_create_multiple_quantity(
+ send_notification_mock,
+ order,
+ gift_card_non_shippable_order_line,
+ site_settings,
+ staff_user,
+):
+ # given
+ manager = get_plugins_manager()
+ quantity = 3
+ gift_card_non_shippable_order_line.quantity = quantity
+ gift_card_non_shippable_order_line.save(update_fields=["quantity"])
+ order_lines = [gift_card_non_shippable_order_line]
+
+ # when
+ gift_cards = gift_cards_create(
+ order, order_lines, site_settings, staff_user, None, manager
+ )
+
+ # then
+ assert len(gift_cards) == quantity
+ assert GiftCardEvent.objects.filter(type=GiftCardEvents.BOUGHT).count() == quantity
+ assert (
+ GiftCardEvent.objects.filter(type=GiftCardEvents.SENT_TO_CUSTOMER).count()
+ == quantity
+ )
+ assert send_notification_mock.call_count == 3
diff --git a/saleor/graphql/order/tests/benchmark/test_order_fulfill.py b/saleor/graphql/order/tests/benchmark/test_order_fulfill.py
new file mode 100644
index 0000000000..a9b787cb26
--- /dev/null
+++ b/saleor/graphql/order/tests/benchmark/test_order_fulfill.py
@@ -0,0 +1,114 @@
+from unittest.mock import patch
+
+import graphene
+import pytest
+
+from ....tests.utils import get_graphql_content
+
+ORDER_FULFILL_QUERY = """
+ mutation fulfillOrder(
+ $order: ID, $input: OrderFulfillInput!
+ ) {
+ orderFulfill(
+ order: $order,
+ input: $input
+ ) {
+ errors {
+ field
+ code
+ message
+ warehouse
+ orderLines
+ }
+ }
+ }
+"""
+
+
[email protected]_queries(autouse=False)
+@patch("saleor.graphql.order.mutations.fulfillments.create_fulfillments")
+def test_order_fulfill(
+ mock_create_fulfillments,
+ staff_api_client,
+ order_with_lines,
+ permission_manage_orders,
+ warehouse,
+ count_queries,
+):
+ order = order_with_lines
+ query = ORDER_FULFILL_QUERY
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ order_line, order_line2 = order.lines.all()
+ order_line_id = graphene.Node.to_global_id("OrderLine", order_line.id)
+ order_line2_id = graphene.Node.to_global_id("OrderLine", order_line2.id)
+ warehouse_id = graphene.Node.to_global_id("Warehouse", warehouse.pk)
+ variables = {
+ "order": order_id,
+ "input": {
+ "notifyCustomer": True,
+ "lines": [
+ {
+ "orderLineId": order_line_id,
+ "stocks": [{"quantity": 3, "warehouse": warehouse_id}],
+ },
+ {
+ "orderLineId": order_line2_id,
+ "stocks": [{"quantity": 2, "warehouse": warehouse_id}],
+ },
+ ],
+ },
+ }
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_orders]
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["orderFulfill"]
+ assert not data["errors"]
+
+
[email protected]_queries(autouse=False)
+@patch("saleor.giftcard.utils.send_gift_card_notification")
+@patch("saleor.graphql.order.mutations.fulfillments.create_fulfillments")
+def test_order_fulfill_with_gift_cards(
+ mock_create_fulfillments,
+ mock_send_notification,
+ staff_api_client,
+ order,
+ gift_card_non_shippable_order_line,
+ gift_card_shippable_order_line,
+ permission_manage_orders,
+ warehouse,
+ count_queries,
+):
+ query = ORDER_FULFILL_QUERY
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ order_line, order_line2 = (
+ gift_card_non_shippable_order_line,
+ gift_card_shippable_order_line,
+ )
+ order_line_id = graphene.Node.to_global_id("OrderLine", order_line.id)
+ order_line2_id = graphene.Node.to_global_id("OrderLine", order_line2.id)
+ warehouse_id = graphene.Node.to_global_id("Warehouse", warehouse.pk)
+ variables = {
+ "order": order_id,
+ "input": {
+ "notifyCustomer": True,
+ "lines": [
+ {
+ "orderLineId": order_line_id,
+ "stocks": [{"quantity": 1, "warehouse": warehouse_id}],
+ },
+ {
+ "orderLineId": order_line2_id,
+ "stocks": [{"quantity": 1, "warehouse": warehouse_id}],
+ },
+ ],
+ },
+ }
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_orders]
+ )
+
+ content = get_graphql_content(response)
+ data = content["data"]["orderFulfill"]
+ assert not data["errors"]
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index 8a64aa2152..27d1da635c 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -2057,7 +2057,9 @@ def variant_with_many_stocks_different_shipping_zones(
@pytest.fixture
def gift_card_shippable_variant(shippable_gift_card_product, channel_USD):
product = shippable_gift_card_product
- product_variant = ProductVariant.objects.create(product=product, sku="SKU_CARD_A")
+ product_variant = ProductVariant.objects.create(
+ product=product, sku="SKU_CARD_A", track_inventory=False
+ )
ProductVariantChannelListing.objects.create(
variant=product_variant,
channel=channel_USD,
@@ -2071,7 +2073,9 @@ def gift_card_shippable_variant(shippable_gift_card_product, channel_USD):
@pytest.fixture
def gift_card_non_shippable_variant(non_shippable_gift_card_product, channel_USD):
product = non_shippable_gift_card_product
- product_variant = ProductVariant.objects.create(product=product, sku="SKU_CARD_B")
+ product_variant = ProductVariant.objects.create(
+ product=product, sku="SKU_CARD_B", track_inventory=False
+ )
ProductVariantChannelListing.objects.create(
variant=product_variant,
channel=channel_USD,