Skip to content

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

Move tests for order's filter-shipping-methods to order module (#18782)

Maciej Korycinskia3e8c93c0840
diff --git a/saleor/order/tests/webhooks/static_payloads/test_order_calculate_taxes.py b/saleor/order/tests/webhooks/static_payloads/test_order_calculate_taxes.py
index 556e4dd410..8a74fc6b17 100644
--- a/saleor/order/tests/webhooks/static_payloads/test_order_calculate_taxes.py
+++ b/saleor/order/tests/webhooks/static_payloads/test_order_calculate_taxes.py
@@ -48,9 +48,7 @@ def order_for_payload(fulfilled_order, voucher_percentage):
@freeze_time()
@pytest.mark.parametrize("prices_entered_with_tax", [True, False])
-# @patch("saleor.order.webhooks.order_calculate_taxes._generate_order_lines_payload_for_tax_calculation")
def test_generate_order_payload_for_tax_calculation(
- # mocked_order_lines,
order_for_payload,
prices_entered_with_tax,
):
diff --git a/saleor/order/tests/webhooks/subscriptions/test_exclude_shipping.py b/saleor/order/tests/webhooks/subscriptions/test_exclude_shipping.py
new file mode 100644
index 0000000000..61c79e6e0b
--- /dev/null
+++ b/saleor/order/tests/webhooks/subscriptions/test_exclude_shipping.py
@@ -0,0 +1,205 @@
+import json
+
+import graphene
+import pytest
+
+from .....shipping.models import ShippingMethodChannelListing
+from .....webhook.event_types import WebhookEventSyncType
+from .....webhook.transport.synchronous.transport import (
+ create_delivery_for_subscription_sync_event,
+)
+from ....delivery_context import get_all_shipping_methods_for_order
+
+ORDER_FILTER_SHIPPING_METHODS = """
+subscription{
+ event{
+ ...on OrderFilterShippingMethods{
+ order{
+ id
+ }
+ shippingMethods{
+ id
+ name
+ }
+ }
+ }
+}
+"""
+
+ORDER_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS = """
+subscription{
+ event{
+ ...on OrderFilterShippingMethods{
+ order{
+ id
+ availableShippingMethods{
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+ORDER_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS = """
+subscription{
+ event{
+ ...on OrderFilterShippingMethods{
+ order{
+ id
+ shippingMethods{
+ id
+ }
+ }
+ }
+ }
+}
+"""
+
+
+def subscription_with_filter_shipping_methods_webhook(subscription_webhook):
+ return subscription_webhook(
+ ORDER_FILTER_SHIPPING_METHODS,
+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,
+ )
+
+
+def subscription_with_shipping_methods(
+ subscription_webhook,
+):
+ return subscription_webhook(
+ ORDER_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS,
+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,
+ )
+
+
+def subscription_with_available_ship_methods(
+ subscription_webhook,
+):
+ return subscription_webhook(
+ ORDER_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS,
+ WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,
+ )
+
+
+def test_order_filter_shipping_methods(
+ order_line_with_one_allocation,
+ subscription_with_filter_shipping_methods_webhook,
+ address,
+):
+ # given
+ order = order_line_with_one_allocation.order
+ order_line_with_one_allocation.is_shipping_required = True
+ order_line_with_one_allocation.save(update_fields=["is_shipping_required"])
+
+ order.currency = "USD"
+ order.shipping_address = address
+ order.save(update_fields=["shipping_address"])
+
+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
+ order_id = graphene.Node.to_global_id("Order", order.pk)
+ all_shipping_methods = get_all_shipping_methods_for_order(
+ order, ShippingMethodChannelListing.objects.all()
+ )
+
+ # when
+ delivery = create_delivery_for_subscription_sync_event(
+ event_type,
+ (order, all_shipping_methods),
+ subscription_with_filter_shipping_methods_webhook,
+ )
+
+ # then
+ shipping_methods = [
+ {
+ "id": graphene.Node.to_global_id("ShippingMethod", sm.id),
+ "name": sm.name,
+ }
+ for sm in all_shipping_methods
+ ]
+ payload = json.loads(delivery.payload.get_payload())
+
+ assert payload["order"] == {"id": order_id}
+ for method in shipping_methods:
+ assert method in payload["shippingMethods"]
+
+ assert delivery.webhook == subscription_with_filter_shipping_methods_webhook
+
+
+def test_order_filter_shipping_methods_no_methods_in_channel(
+ order_line_with_one_allocation,
+ subscription_with_filter_shipping_methods_webhook,
+ shipping_method_channel_PLN,
+):
+ # given
+ order = order_line_with_one_allocation.order
+ order.save(update_fields=["shipping_address"])
+
+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
+ order_id = graphene.Node.to_global_id("Order", order.pk)
+
+ # when
+ delivery = create_delivery_for_subscription_sync_event(
+ event_type, (order, []), subscription_with_filter_shipping_methods_webhook
+ )
+
+ # then
+ expected_payload = {"order": {"id": order_id}, "shippingMethods": []}
+
+ assert json.loads(delivery.payload.get_payload()) == expected_payload
+ assert delivery.webhook == subscription_with_filter_shipping_methods_webhook
+
+
+def test_order_filter_shipping_methods_with_circular_call_for_available_methods(
+ order_line_with_one_allocation,
+ subscription_with_available_ship_methods,
+):
+ # given
+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
+ order = order_line_with_one_allocation.order
+
+ # when
+ delivery = create_delivery_for_subscription_sync_event(
+ event_type,
+ (order, []),
+ subscription_with_available_ship_methods,
+ )
+
+ # then
+ payload = json.loads(delivery.payload.get_payload())
+
+ assert len(payload["errors"]) == 1
+ assert (
+ payload["errors"][0]["message"]
+ == "Resolving this field is not allowed in synchronous events."
+ )
+
+
+def test_order_filter_shipping_methods_with_circular_call_for_shipping_methods(
+ order_line_with_one_allocation,
+ subscription_with_shipping_methods,
+):
+ # given
+
+ event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
+ order = order_line_with_one_allocation.order
+
+ # when
+ delivery = create_delivery_for_subscription_sync_event(
+ event_type,
+ (order, []),
+ subscription_with_shipping_methods,
+ )
+
+ # then
+ payload = json.loads(delivery.payload.get_payload())
+
+ assert len(payload["errors"]) == 1
+ assert (
+ payload["errors"][0]["message"]
+ == "Resolving this field is not allowed in synchronous events."
+ )
+ assert payload["order"] is None
diff --git a/saleor/order/tests/webhooks/test_exclude_shipping_cache.py b/saleor/order/tests/webhooks/test_exclude_shipping_cache.py
index bf8d1c087d..30d473f1ae 100644
--- a/saleor/order/tests/webhooks/test_exclude_shipping_cache.py
+++ b/saleor/order/tests/webhooks/test_exclude_shipping_cache.py
@@ -18,24 +18,27 @@ from ...webhooks.exclude_shipping import (
@pytest.fixture
-def available_shipping_methods_factory():
- def factory(num_methods=1) -> list[ShippingMethodData]:
- methods = []
- for i in range(num_methods):
- methods.append(
- ShippingMethodData(
- id=str(i),
- price=Money(Decimal(10), "usd"),
- name=uuid.uuid4().hex,
- maximum_order_weight=Weight(kg=0),
- minimum_order_weight=Weight(kg=0),
- maximum_delivery_days=0,
- minimum_delivery_days=5,
- )
- )
- return methods
-
- return factory
+def available_shipping_methods():
+ return [
+ ShippingMethodData(
+ id="1",
+ price=Money(Decimal(10), "usd"),
+ name=uuid.uuid4().hex,
+ maximum_order_weight=Weight(kg=0),
+ minimum_order_weight=Weight(kg=0),
+ maximum_delivery_days=0,
+ minimum_delivery_days=5,
+ ),
+ ShippingMethodData(
+ id="2",
+ price=Money(Decimal(10), "usd"),
+ name=uuid.uuid4().hex,
+ maximum_order_weight=Weight(kg=0),
+ minimum_order_weight=Weight(kg=0),
+ maximum_delivery_days=0,
+ minimum_delivery_days=5,
+ ),
+ ]
@mock.patch("saleor.webhook.transport.synchronous.transport.cache.get")
@@ -50,7 +53,7 @@ def test_excluded_shipping_methods_for_order_use_cache(
mocked_cache_set,
mocked_cache_get,
order_with_lines,
- available_shipping_methods_factory,
+ available_shipping_methods,
app_exclude_shipping_for_order,
):
# given
@@ -70,8 +73,6 @@ def test_excluded_shipping_methods_for_order_use_cache(
mocked_cache_get.return_value = (payload, [{"id": "1", "reason": webhook_reason}])
- available_shipping_methods = available_shipping_methods_factory(num_methods=2)
-
# when
excluded_shipping_methods_for_order(
order=order_with_lines,
@@ -98,7 +99,7 @@ def test_excluded_shipping_methods_for_order_stores_in_cache_when_empty(
mocked_cache_set,
mocked_cache_get,
order_with_lines,
- available_shipping_methods_factory,
+ available_shipping_methods,
app_exclude_shipping_for_order,
):
# given
@@ -123,8 +124,6 @@ def test_excluded_shipping_methods_for_order_stores_in_cache_when_empty(
mocked_cache_get.return_value = None
- available_shipping_methods = available_shipping_methods_factory(num_methods=2)
-
# when
excluded_shipping_methods_for_order(
order=order_with_lines,
@@ -162,7 +161,7 @@ def test_excluded_shipping_methods_for_order_stores_in_cache_when_payload_is_dif
mocked_cache_set,
mocked_cache_get,
order_with_lines,
- available_shipping_methods_factory,
+ available_shipping_methods,
app_exclude_shipping_for_order,
):
# given
@@ -185,8 +184,6 @@ def test_excluded_shipping_methods_for_order_stores_in_cache_when_payload_is_dif
mocked_cache_get.return_value = None
- available_shipping_methods = available_shipping_methods_factory(num_methods=2)
-
# when
excluded_shipping_methods_for_order(
order=order_with_lines,
diff --git a/saleor/webhook/tests/fixtures/subscription_webhooks.py b/saleor/webhook/tests/fixtures/subscription_webhooks.py
index 6c6e0797bd..f430f84848 100644
--- a/saleor/webhook/tests/fixtures/subscription_webhooks.py
+++ b/saleor/webhook/tests/fixtures/subscription_webhooks.py
@@ -1317,14 +1317,6 @@ def subscription_shipping_list_methods_for_checkout_webhook(subscription_webhook
)
-def subscription_order_filter_shipping_methods_webhook(subscription_webhook):
- return subscription_webhook(
- queries.ORDER_FILTER_SHIPPING_METHODS,
- WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,
- )
-
-
@pytest.fixture
def subscription_checkout_filter_shipping_method_webhook_with_shipping_methods(
subscription_webhook,
@@ -1355,26 +1347,6 @@ def subscription_checkout_filter_shipping_method_webhook_with_payment_gateways(
)
-def subscription_order_filter_shipping_methods_webhook_with_shipping_methods(
- subscription_webhook,
-):
- return subscription_webhook(
- queries.ORDER_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS,
- WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,
- )
-
-
-def subscription_order_filter_shipping_methods_webhook_with_available_ship_methods(
- subscription_webhook,
-):
- return subscription_webhook(
- queries.ORDER_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS,
- WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS,
- )
-
-
@pytest.fixture
def subscription_thumbnail_created_webhook(subscription_webhook):
return subscription_webhook(
diff --git a/saleor/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/webhook/tests/subscription_webhooks/subscription_queries.py
index 0a5ef7d627..5e56f43595 100644
--- a/saleor/webhook/tests/subscription_webhooks/subscription_queries.py
+++ b/saleor/webhook/tests/subscription_webhooks/subscription_queries.py
@@ -3083,22 +3083,6 @@ PAYMENT_LIST_GATEWAYS = """
}
"""
-ORDER_FILTER_SHIPPING_METHODS = """
-subscription{
- event{
- ...on OrderFilterShippingMethods{
- order{
- id
- }
- shippingMethods{
- id
- name
- }
- }
- }
-}
-"""
-
CHECKOUT_FILTER_SHIPPING_METHODS = """
subscription{
@@ -3179,36 +3163,6 @@ subscription{
}
"""
-ORDER_FILTER_SHIPPING_METHODS_AVAILABLE_SHIPPING_METHODS = """
-subscription{
- event{
- ...on OrderFilterShippingMethods{
- order{
- id
- availableShippingMethods{
- id
- }
- }
- }
- }
-}
-"""
-
-ORDER_FILTER_SHIPPING_METHODS_CIRCULAR_SHIPPING_METHODS = """
-subscription{
- event{
- ...on OrderFilterShippingMethods{
- order{
- id
- shippingMethods{
- id
- }
- }
- }
- }
-}
-"""
-
INVALID_MULTIPLE_EVENTS = """
subscription{
diff --git a/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py b/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py
index a4487dce34..f26b091ced 100644
--- a/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py
+++ b/saleor/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py
@@ -11,12 +11,10 @@ from ....channel.models import Channel
from ....giftcard.models import GiftCard
from ....graphql.webhook.subscription_query import SubscriptionQuery
from ....menu.models import Menu, MenuItem
-from ....order.delivery_context import get_all_shipping_methods_for_order
from ....product.models import Category
from ....shipping.interface import ShippingMethodData
from ....shipping.models import (
ShippingMethod,
- ShippingMethodChannelListing,
ShippingZone,
)
from ....shipping.utils import convert_to_shipping_method_data
@@ -3078,120 +3076,6 @@ def test_checkout_list_methods_mismatch_in_subscription_query_definition(
assert not deliveries
-def test_order_filter_shipping_methods(
- order_line_with_one_allocation,
- subscription_order_filter_shipping_methods_webhook,
- address,
-):
- # given
- order = order_line_with_one_allocation.order
- order_line_with_one_allocation.is_shipping_required = True
- order_line_with_one_allocation.save(update_fields=["is_shipping_required"])
-
- order.currency = "USD"
- order.shipping_address = address
- order.save(update_fields=["shipping_address"])
- webhooks = [subscription_order_filter_shipping_methods_webhook]
- event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
- order_id = graphene.Node.to_global_id("Order", order.pk)
- all_shipping_methods = get_all_shipping_methods_for_order(
- order, ShippingMethodChannelListing.objects.all()
- )
-
- # when
- deliveries = create_deliveries_for_subscriptions(
- event_type, (order, all_shipping_methods), webhooks
- )
-
- # then
- shipping_methods = [
- {
- "id": graphene.Node.to_global_id("ShippingMethod", sm.id),
- "name": sm.name,
- }
- for sm in all_shipping_methods
- ]
- payload = json.loads(deliveries[0].payload.get_payload())
-
- assert payload["order"] == {"id": order_id}
- for method in shipping_methods:
- assert method in payload["shippingMethods"]
- assert len(deliveries) == len(webhooks)
- assert deliveries[0].webhook == webhooks[0]
-
-
-def test_order_filter_shipping_methods_no_methods_in_channel(
- order_line_with_one_allocation,
- subscription_order_filter_shipping_methods_webhook,
- shipping_method_channel_PLN,
-):
- # given
- order = order_line_with_one_allocation.order
- order.save(update_fields=["shipping_address"])
- webhooks = [subscription_order_filter_shipping_methods_webhook]
- event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
- order_id = graphene.Node.to_global_id("Order", order.pk)
-
- # when
- deliveries = create_deliveries_for_subscriptions(event_type, (order, []), webhooks)
-
- # then
- expected_payload = {"order": {"id": order_id}, "shippingMethods": []}
-
- assert json.loads(deliveries[0].payload.get_payload()) == expected_payload
- assert len(deliveries) == len(webhooks)
- assert deliveries[0].webhook == webhooks[0]
-
-
-def test_order_filter_shipping_methods_with_circular_call_for_available_methods(
- order_line_with_one_allocation,
- subscription_order_filter_shipping_methods_webhook_with_available_ship_methods,
-):
- # given
- webhooks = [
- subscription_order_filter_shipping_methods_webhook_with_available_ship_methods
- ]
- event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
- order = order_line_with_one_allocation.order
-
- # when
- deliveries = create_deliveries_for_subscriptions(event_type, (order, []), webhooks)
-
- # then
- payload = json.loads(deliveries[0].payload.get_payload())
-
- assert len(payload["errors"]) == 1
- assert (
- payload["errors"][0]["message"]
- == "Resolving this field is not allowed in synchronous events."
- )
-
-
-def test_order_filter_shipping_methods_with_circular_call_for_shipping_methods(
- order_line_with_one_allocation,
- subscription_order_filter_shipping_methods_webhook_with_shipping_methods,
-):
- # given
- webhooks = [
- subscription_order_filter_shipping_methods_webhook_with_shipping_methods
- ]
- event_type = WebhookEventSyncType.ORDER_FILTER_SHIPPING_METHODS
- order = order_line_with_one_allocation.order
-
- # when
- deliveries = create_deliveries_for_subscriptions(event_type, (order, []), webhooks)
-
- # then
- payload = json.loads(deliveries[0].payload.get_payload())
-
- assert len(payload["errors"]) == 1
- assert (
- payload["errors"][0]["message"]
- == "Resolving this field is not allowed in synchronous events."
- )
- assert payload["order"] is None
-
-
@patch.object(logger, "info")
def test_create_deliveries_for_subscriptions_unsubscribable_event(
mocked_logger, product, subscription_product_updated_webhook, any_webhook