Skip to content

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

Clean up the input arguments for order and checkout call_event logic (#16489)

Maciej Korycinski1acc7c2dc1d7
diff --git a/saleor/checkout/actions.py b/saleor/checkout/actions.py
index f68dc135d3..eee70bee99 100644
--- a/saleor/checkout/actions.py
+++ b/saleor/checkout/actions.py
@@ -1,7 +1,7 @@
from collections.abc import Iterable
from datetime import timedelta
from decimal import Decimal
-from typing import TYPE_CHECKING, Callable, Optional, cast
+from typing import TYPE_CHECKING, Optional, cast
from django.utils import timezone
@@ -25,24 +25,37 @@ from .payment_utils import update_refundable_for_checkout
if TYPE_CHECKING:
from ..account.models import Address
- from ..plugins.manager import PluginsManager
from ..webhook.models import Webhook
+from ..plugins.manager import PluginsManager
-def call_checkout_event_for_checkout(
+CHECKOUT_WEBHOOK_EVENT_MAP = {
+ WebhookEventAsyncType.CHECKOUT_CREATED: PluginsManager.checkout_created.__name__,
+ WebhookEventAsyncType.CHECKOUT_UPDATED: PluginsManager.checkout_updated.__name__,
+ WebhookEventAsyncType.CHECKOUT_FULLY_PAID: PluginsManager.checkout_fully_paid.__name__,
+ WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED: PluginsManager.checkout_metadata_updated.__name__,
+}
+
+
+def call_checkout_event(
manager: "PluginsManager",
- event_func: Callable,
event_name: str,
checkout: "Checkout",
):
+ if event_name not in CHECKOUT_WEBHOOK_EVENT_MAP:
+ raise ValueError(f"Event {event_name} not found in CHECKOUT_WEBHOOK_EVENT_MAP.")
+
webhook_event_map = get_webhooks_for_multiple_events(
[event_name, *WebhookEventSyncType.CHECKOUT_EVENTS]
)
+
if not webhook_async_event_requires_sync_webhooks_to_trigger(
event_name,
webhook_event_map,
possible_sync_events=WebhookEventSyncType.CHECKOUT_EVENTS,
):
+ plugin_manager_method_name = CHECKOUT_WEBHOOK_EVENT_MAP[event_name]
+ event_func = getattr(manager, plugin_manager_method_name)
call_event_including_protected_events(event_func, checkout)
return
@@ -54,9 +67,8 @@ def call_checkout_event_for_checkout(
lines_info,
manager,
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager=manager,
- event_func=event_func,
event_name=event_name,
checkout_info=checkout_info,
lines=lines_info,
@@ -65,9 +77,8 @@ def call_checkout_event_for_checkout(
return
-def call_checkout_event_for_checkout_info(
+def call_checkout_info_event(
manager: "PluginsManager",
- event_func: Callable,
event_name: str,
checkout_info: "CheckoutInfo",
lines: Iterable["CheckoutLineInfo"],
@@ -79,6 +90,11 @@ def call_checkout_event_for_checkout_info(
webhook_event_map = get_webhooks_for_multiple_events(
[event_name, *WebhookEventSyncType.CHECKOUT_EVENTS]
)
+ if event_name not in CHECKOUT_WEBHOOK_EVENT_MAP:
+ raise ValueError(f"Event {event_name} not found in CHECKOUT_WEBHOOK_EVENT_MAP.")
+
+ plugin_manager_method_name = CHECKOUT_WEBHOOK_EVENT_MAP[event_name]
+ event_func = getattr(manager, plugin_manager_method_name)
# No need to trigger additional sync webhook when we don't have active webhook or
# we don't have active sync checkout webhooks
@@ -156,9 +172,8 @@ def transaction_amounts_for_checkout_updated(
update_refundable_for_checkout(checkout.pk)
if not previous_charge_status_is_fully_paid and current_status_is_fully_paid:
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_fully_paid,
event_name=WebhookEventAsyncType.CHECKOUT_FULLY_PAID,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/checkout/tests/test_actions.py b/saleor/checkout/tests/test_actions.py
index d6129b4ad4..ec6e5a0589 100644
--- a/saleor/checkout/tests/test_actions.py
+++ b/saleor/checkout/tests/test_actions.py
@@ -14,8 +14,8 @@ from ...tests.utils import flush_post_commit_hooks
from ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from .. import CheckoutAuthorizeStatus, CheckoutChargeStatus
from ..actions import (
- call_checkout_event_for_checkout,
- call_checkout_event_for_checkout_info,
+ call_checkout_event,
+ call_checkout_info_event,
transaction_amounts_for_checkout_updated,
)
from ..calculations import fetch_checkout_data
@@ -304,12 +304,53 @@ def test_get_checkout_refundable_with_multiple_active_transactions(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_triggers_sync_webhook_when_needed(
+def test_call_checkout_event_incorrect_webhook_event(
+ mocked_send_webhook_request_async,
+ mocked_send_webhook_request_sync,
+ checkout_with_items,
+ setup_checkout_webhooks,
+ django_capture_on_commit_callbacks,
+):
+ # given
+ plugins_manager = get_plugins_manager(allow_replica=False)
+ checkout_with_items.price_expiration = timezone.now()
+ checkout_with_items.save(update_fields=["price_expiration"])
+
+ mocked_send_webhook_request_sync.return_value = []
+ setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_CREATED)
+
+ incorrect_event = WebhookEventAsyncType.ORDER_UPDATED
+ # when
+
+ with django_capture_on_commit_callbacks(execute=True):
+ with pytest.raises(
+ ValueError,
+ match=f"Event {incorrect_event} not found in CHECKOUT_WEBHOOK_EVENT_MAP.",
+ ):
+ call_checkout_event(
+ plugins_manager,
+ incorrect_event,
+ checkout_with_items,
+ )
+
+ # then
+ assert not mocked_send_webhook_request_async.called
+ assert not mocked_send_webhook_request_sync.called
+
+
+@freeze_time("2023-05-31 12:00:01")
+@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_call_checkout_event_triggers_sync_webhook_when_needed(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
setup_checkout_webhooks,
settings,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -325,17 +366,15 @@ def test_call_checkout_event_for_checkout_triggers_sync_webhook_when_needed(
) = setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_CREATED)
# when
- with freeze_time("2023-06-01 12:00:01"):
- call_checkout_event_for_checkout(
- plugins_manager,
- plugins_manager.checkout_created,
- WebhookEventAsyncType.CHECKOUT_CREATED,
- checkout_with_items,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ with freeze_time("2023-06-01 12:00:01"):
+ call_checkout_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_CREATED,
+ checkout_with_items,
+ )
# then
- flush_post_commit_hooks()
-
# confirm that event delivery was generated for each webhook.
checkout_create_delivery = EventDelivery.objects.get(
webhook_id=checkout_created_webhook.id
@@ -372,12 +411,13 @@ def test_call_checkout_event_for_checkout_triggers_sync_webhook_when_needed(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_skips_tax_webhook_when_not_expired(
+def test_call_checkout_event_skips_tax_webhook_when_not_expired(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
setup_checkout_webhooks,
settings,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -393,16 +433,14 @@ def test_call_checkout_event_for_checkout_skips_tax_webhook_when_not_expired(
) = setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_CREATED)
# when
- call_checkout_event_for_checkout(
- plugins_manager,
- plugins_manager.checkout_created,
- WebhookEventAsyncType.CHECKOUT_CREATED,
- checkout_with_items,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ call_checkout_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_CREATED,
+ checkout_with_items,
+ )
# then
- flush_post_commit_hooks()
-
# confirm that event delivery was generated for each webhook.
checkout_create_delivery = EventDelivery.objects.get(
webhook_id=checkout_created_webhook.id
@@ -439,12 +477,12 @@ def test_call_checkout_event_for_checkout_skips_tax_webhook_when_not_expired(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_skip_sync_webhooks_when_async_missing(
+def test_call_checkout_event_skip_sync_webhooks_when_async_missing(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
setup_checkout_webhooks,
- settings,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -457,16 +495,15 @@ def test_call_checkout_event_for_checkout_skip_sync_webhooks_when_async_missing(
setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_CREATED)
# when
- with freeze_time("2023-06-01 12:00:01"):
- call_checkout_event_for_checkout(
- plugins_manager,
- plugins_manager.checkout_updated,
- WebhookEventAsyncType.CHECKOUT_UPDATED,
- checkout_with_items,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ with freeze_time("2023-06-01 12:00:01"):
+ call_checkout_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_UPDATED,
+ checkout_with_items,
+ )
# then
- flush_post_commit_hooks()
assert not mocked_send_webhook_request_async.called
assert not mocked_send_webhook_request_sync.called
@@ -485,6 +522,7 @@ def test_call_checkout_event_only_async_when_sync_missing(
permission_manage_checkouts,
settings,
webhook,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -495,16 +533,15 @@ def test_call_checkout_event_only_async_when_sync_missing(
webhook.app.permissions.add(permission_manage_checkouts)
# when
- with freeze_time("2023-06-01 12:00:01"):
- call_checkout_event_for_checkout(
- plugins_manager,
- plugins_manager.checkout_created,
- WebhookEventAsyncType.CHECKOUT_CREATED,
- checkout_with_items,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ with freeze_time("2023-06-01 12:00:01"):
+ call_checkout_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_CREATED,
+ checkout_with_items,
+ )
# then
- flush_post_commit_hooks()
# confirm that event delivery was generated for each webhook.
checkout_create_delivery = EventDelivery.objects.get(webhook_id=webhook.id)
@@ -525,12 +562,62 @@ def test_call_checkout_event_only_async_when_sync_missing(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_info_triggers_sync_webhook_when_needed(
+def test_call_checkout_info_event_incorrect_webhook_event(
+ mocked_send_webhook_request_async,
+ mocked_send_webhook_request_sync,
+ checkout_with_items,
+ setup_checkout_webhooks,
+ django_capture_on_commit_callbacks,
+):
+ # given
+ plugins_manager = get_plugins_manager(allow_replica=False)
+ checkout_with_items.price_expiration = timezone.now()
+ checkout_with_items.save(update_fields=["price_expiration"])
+
+ mocked_send_webhook_request_sync.return_value = []
+ setup_checkout_webhooks(WebhookEventAsyncType.CHECKOUT_CREATED)
+
+ lines_info, _ = fetch_checkout_lines(
+ checkout_with_items,
+ )
+ checkout_info = fetch_checkout_info(
+ checkout_with_items,
+ lines_info,
+ plugins_manager,
+ )
+ incorrect_webhook_event = WebhookEventAsyncType.ORDER_UPDATED
+
+ # when
+ with django_capture_on_commit_callbacks(execute=True):
+ with pytest.raises(
+ ValueError,
+ match=f"Event {incorrect_webhook_event} not found in CHECKOUT_WEBHOOK_EVENT_MAP.",
+ ):
+ call_checkout_info_event(
+ plugins_manager,
+ incorrect_webhook_event,
+ checkout_info,
+ lines_info,
+ )
+
+ # then
+ assert not mocked_send_webhook_request_async.called
+ assert not mocked_send_webhook_request_sync.called
+
+
+@freeze_time("2023-05-31 12:00:01")
+@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_call_checkout_info_event_triggers_sync_webhook_when_needed(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
setup_checkout_webhooks,
settings,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -555,17 +642,16 @@ def test_call_checkout_event_for_checkout_info_triggers_sync_webhook_when_needed
)
# when
- with freeze_time("2023-06-01 12:00:01"):
- call_checkout_event_for_checkout_info(
- plugins_manager,
- plugins_manager.checkout_created,
- WebhookEventAsyncType.CHECKOUT_CREATED,
- checkout_info,
- lines_info,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ with freeze_time("2023-06-01 12:00:01"):
+ call_checkout_info_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_CREATED,
+ checkout_info,
+ lines_info,
+ )
# then
- flush_post_commit_hooks()
# confirm that event delivery was generated for each webhook.
checkout_create_delivery = EventDelivery.objects.get(
@@ -603,12 +689,13 @@ def test_call_checkout_event_for_checkout_info_triggers_sync_webhook_when_needed
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_info_skips_tax_webhook_when_not_expired(
+def test_call_checkout_info_event_skips_tax_webhook_when_not_expired(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
setup_checkout_webhooks,
settings,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -633,16 +720,15 @@ def test_call_checkout_event_for_checkout_info_skips_tax_webhook_when_not_expire
)
# when
- call_checkout_event_for_checkout_info(
- plugins_manager,
- plugins_manager.checkout_created,
- WebhookEventAsyncType.CHECKOUT_CREATED,
- checkout_info,
- lines_info,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ call_checkout_info_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_CREATED,
+ checkout_info,
+ lines_info,
+ )
# then
- flush_post_commit_hooks()
# confirm that event delivery was generated for each webhook.
checkout_create_delivery = EventDelivery.objects.get(
@@ -680,13 +766,14 @@ def test_call_checkout_event_for_checkout_info_skips_tax_webhook_when_not_expire
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_info_only_async_when_sync_missing(
+def test_call_checkout_info_event_only_async_when_sync_missing(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
permission_manage_checkouts,
settings,
webhook,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -706,17 +793,16 @@ def test_call_checkout_event_for_checkout_info_only_async_when_sync_missing(
)
# when
- with freeze_time("2023-06-01 12:00:01"):
- call_checkout_event_for_checkout_info(
- plugins_manager,
- plugins_manager.checkout_created,
- WebhookEventAsyncType.CHECKOUT_CREATED,
- checkout_info,
- lines_info,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ with freeze_time("2023-06-01 12:00:01"):
+ call_checkout_info_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_CREATED,
+ checkout_info,
+ lines_info,
+ )
# then
- flush_post_commit_hooks()
# confirm that event delivery was generated for each webhook.
checkout_create_delivery = EventDelivery.objects.get(webhook_id=webhook.id)
@@ -737,12 +823,12 @@ def test_call_checkout_event_for_checkout_info_only_async_when_sync_missing(
"saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
)
@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
-def test_call_checkout_event_for_checkout_info_skip_sync_webhooks_when_async_missing(
+def test_call_checkout_info_event_skip_sync_webhooks_when_async_missing(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
checkout_with_items,
setup_checkout_webhooks,
- settings,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -764,17 +850,16 @@ def test_call_checkout_event_for_checkout_info_skip_sync_webhooks_when_async_mis
)
# when
- with freeze_time("2023-06-01 12:00:01"):
- call_checkout_event_for_checkout_info(
- plugins_manager,
- plugins_manager.checkout_updated,
- WebhookEventAsyncType.CHECKOUT_UPDATED,
- checkout_info,
- lines_info,
- )
+ with django_capture_on_commit_callbacks(execute=True):
+ with freeze_time("2023-06-01 12:00:01"):
+ call_checkout_info_event(
+ plugins_manager,
+ WebhookEventAsyncType.CHECKOUT_UPDATED,
+ checkout_info,
+ lines_info,
+ )
# then
- flush_post_commit_hooks()
assert not mocked_send_webhook_request_async.called
assert not mocked_send_webhook_request_sync.called
@@ -782,8 +867,8 @@ def test_call_checkout_event_for_checkout_info_skip_sync_webhooks_when_async_mis
@freeze_time("2023-05-31 12:00:01")
@patch(
- "saleor.checkout.actions.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.checkout.actions.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -793,11 +878,12 @@ def test_call_checkout_event_for_checkout_info_skip_sync_webhooks_when_async_mis
def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
checkout_with_items,
transaction_item_generator,
+ django_capture_on_commit_callbacks,
):
# given
plugins_manager = get_plugins_manager(allow_replica=False)
@@ -820,10 +906,10 @@ def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(
)
# when
- transaction_amounts_for_checkout_updated(transaction, manager=plugins_manager)
+ with django_capture_on_commit_callbacks(execute=True):
+ transaction_amounts_for_checkout_updated(transaction, manager=plugins_manager)
# then
- flush_post_commit_hooks()
# confirm that event delivery was generated for each webhook.
checkout_fully_paid_delivery = EventDelivery.objects.get(
@@ -853,4 +939,4 @@ def test_transaction_amounts_for_checkout_fully_paid_triggers_sync_webhook(
call(filter_shipping_delivery, timeout=settings.WEBHOOK_SYNC_TIMEOUT),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/mutations/checkout_add_promo_code.py b/saleor/graphql/checkout/mutations/checkout_add_promo_code.py
index 7621c418d9..505ea15a9b 100644
--- a/saleor/graphql/checkout/mutations/checkout_add_promo_code.py
+++ b/saleor/graphql/checkout/mutations/checkout_add_promo_code.py
@@ -1,7 +1,7 @@
import graphene
from django.core.exceptions import ValidationError
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import (
fetch_checkout_info,
@@ -121,9 +121,8 @@ class CheckoutAddPromoCode(BaseMutation):
recalculate_discount=False,
save=True,
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager=manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py b/saleor/graphql/checkout/mutations/checkout_billing_address_update.py
index d9cdefa678..8f55fe3511 100644
--- a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_billing_address_update.py
@@ -1,7 +1,7 @@
import graphene
from ....checkout import AddressType
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import change_billing_address_in_checkout, invalidate_checkout
from ....core.tracing import traced_atomic_transaction
@@ -108,9 +108,8 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):
+ invalidate_prices_updated_fields
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager=manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_create.py b/saleor/graphql/checkout/mutations/checkout_create.py
index 59644474b9..4ff538b219 100644
--- a/saleor/graphql/checkout/mutations/checkout_create.py
+++ b/saleor/graphql/checkout/mutations/checkout_create.py
@@ -4,7 +4,7 @@ import graphene
from django.conf import settings
from ....checkout import AddressType, models
-from ....checkout.actions import call_checkout_event_for_checkout
+from ....checkout.actions import call_checkout_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.utils import add_variants_to_checkout
from ....core.tracing import traced_atomic_transaction
@@ -408,9 +408,8 @@ class CheckoutCreate(ModelMutation, I18nMixin):
checkout = response.checkout
apply_gift_reward_if_applicable_on_checkout_creation(response.checkout)
manager = get_plugin_manager_promise(info.context).get()
- call_checkout_event_for_checkout(
+ call_checkout_event(
manager,
- event_func=manager.checkout_created,
event_name=WebhookEventAsyncType.CHECKOUT_CREATED,
checkout=checkout,
)
diff --git a/saleor/graphql/checkout/mutations/checkout_customer_attach.py b/saleor/graphql/checkout/mutations/checkout_customer_attach.py
index 843d9b5e6f..efd4921cdb 100644
--- a/saleor/graphql/checkout/mutations/checkout_customer_attach.py
+++ b/saleor/graphql/checkout/mutations/checkout_customer_attach.py
@@ -1,7 +1,7 @@
import graphene
from django.forms import ValidationError
-from ....checkout.actions import call_checkout_event_for_checkout
+from ....checkout.actions import call_checkout_event
from ....checkout.error_codes import CheckoutErrorCode
from ....core.exceptions import PermissionDenied
from ....permission.auth_filters import AuthorizationFilters
@@ -118,9 +118,8 @@ class CheckoutCustomerAttach(BaseMutation):
checkout.save(update_fields=["email", "user", "last_change"])
manager = get_plugin_manager_promise(info.context).get()
- call_checkout_event_for_checkout(
+ call_checkout_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout=checkout,
)
diff --git a/saleor/graphql/checkout/mutations/checkout_customer_detach.py b/saleor/graphql/checkout/mutations/checkout_customer_detach.py
index 4c1b58b8a7..e4bb277afa 100644
--- a/saleor/graphql/checkout/mutations/checkout_customer_detach.py
+++ b/saleor/graphql/checkout/mutations/checkout_customer_detach.py
@@ -1,8 +1,6 @@
import graphene
-from ....checkout.actions import (
- call_checkout_event_for_checkout,
-)
+from ....checkout.actions import call_checkout_event
from ....core.exceptions import PermissionDenied
from ....permission.auth_filters import AuthorizationFilters
from ....permission.enums import AccountPermissions
@@ -72,9 +70,8 @@ class CheckoutCustomerDetach(BaseMutation):
checkout.save(update_fields=["user", "last_change"])
manager = get_plugin_manager_promise(info.context).get()
- call_checkout_event_for_checkout(
+ call_checkout_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout=checkout,
)
diff --git a/saleor/graphql/checkout/mutations/checkout_customer_note_update.py b/saleor/graphql/checkout/mutations/checkout_customer_note_update.py
index 4035064719..0c8d14f528 100644
--- a/saleor/graphql/checkout/mutations/checkout_customer_note_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_customer_note_update.py
@@ -1,6 +1,6 @@
import graphene
-from ....checkout.actions import call_checkout_event_for_checkout
+from ....checkout.actions import call_checkout_event
from ....webhook.event_types import WebhookEventAsyncType
from ...core import ResolveInfo
from ...core.descriptions import ADDED_IN_321
@@ -54,9 +54,8 @@ class CheckoutCustomerNoteUpdate(BaseMutation):
cls.clean_instance(info, checkout)
checkout.save(update_fields=["note", "last_change"])
manager = get_plugin_manager_promise(info.context).get()
- call_checkout_event_for_checkout(
+ call_checkout_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout=checkout,
)
diff --git a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
index 02ff68a544..b052fba239 100644
--- a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
@@ -4,7 +4,7 @@ from typing import Optional
import graphene
from django.core.exceptions import ValidationError
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import (
CheckoutInfo,
@@ -270,9 +270,8 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):
update_fields=checkout_fields_to_update + invalidate_prices_updated_fields
)
get_or_create_checkout_metadata(checkout).save()
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_email_update.py b/saleor/graphql/checkout/mutations/checkout_email_update.py
index 49d222336a..ce35f882b5 100644
--- a/saleor/graphql/checkout/mutations/checkout_email_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_email_update.py
@@ -1,7 +1,7 @@
import graphene
from django.core.exceptions import ValidationError
-from ....checkout.actions import call_checkout_event_for_checkout
+from ....checkout.actions import call_checkout_event
from ....checkout.error_codes import CheckoutErrorCode
from ....webhook.event_types import WebhookEventAsyncType
from ...core import ResolveInfo
@@ -80,9 +80,8 @@ class CheckoutEmailUpdate(BaseMutation):
cls.clean_instance(info, checkout)
checkout.save(update_fields=["email", "last_change"])
manager = get_plugin_manager_promise(info.context).get()
- call_checkout_event_for_checkout(
+ call_checkout_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout=checkout,
)
diff --git a/saleor/graphql/checkout/mutations/checkout_language_code_update.py b/saleor/graphql/checkout/mutations/checkout_language_code_update.py
index 07614b8167..0021bc7ba0 100644
--- a/saleor/graphql/checkout/mutations/checkout_language_code_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_language_code_update.py
@@ -1,6 +1,6 @@
import graphene
-from saleor.checkout.actions import call_checkout_event_for_checkout
+from saleor.checkout.actions import call_checkout_event
from saleor.webhook.event_types import WebhookEventAsyncType
from ...core import ResolveInfo
@@ -67,9 +67,8 @@ class CheckoutLanguageCodeUpdate(BaseMutation):
checkout.language_code = language_code
checkout.save(update_fields=["language_code", "last_change"])
manager = get_plugin_manager_promise(info.context).get()
- call_checkout_event_for_checkout(
+ call_checkout_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout=checkout,
)
diff --git a/saleor/graphql/checkout/mutations/checkout_line_delete.py b/saleor/graphql/checkout/mutations/checkout_line_delete.py
index 40fc469afa..6c57be72fa 100644
--- a/saleor/graphql/checkout/mutations/checkout_line_delete.py
+++ b/saleor/graphql/checkout/mutations/checkout_line_delete.py
@@ -1,6 +1,6 @@
import graphene
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import invalidate_checkout
@@ -82,9 +82,8 @@ class CheckoutLineDelete(BaseMutation):
checkout_info = fetch_checkout_info(checkout, lines, manager)
update_checkout_shipping_method_if_invalid(checkout_info, lines)
invalidate_checkout(checkout_info, lines, manager, save=True)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_lines_add.py b/saleor/graphql/checkout/mutations/checkout_lines_add.py
index 26883b84ce..9e808eaddd 100644
--- a/saleor/graphql/checkout/mutations/checkout_lines_add.py
+++ b/saleor/graphql/checkout/mutations/checkout_lines_add.py
@@ -1,6 +1,6 @@
import graphene
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import (
fetch_checkout_info,
@@ -216,9 +216,8 @@ class CheckoutLinesAdd(BaseMutation):
update_checkout_external_shipping_method_if_invalid(checkout_info, lines)
update_checkout_shipping_method_if_invalid(checkout_info, lines)
invalidate_checkout(checkout_info, lines, manager, save=True)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_lines_delete.py b/saleor/graphql/checkout/mutations/checkout_lines_delete.py
index d93fab0394..adb4b649f9 100644
--- a/saleor/graphql/checkout/mutations/checkout_lines_delete.py
+++ b/saleor/graphql/checkout/mutations/checkout_lines_delete.py
@@ -1,7 +1,7 @@
import graphene
from django.core.exceptions import ValidationError
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import invalidate_checkout
@@ -101,9 +101,8 @@ class CheckoutLinesDelete(BaseMutation):
checkout_info = fetch_checkout_info(checkout, lines, manager)
update_checkout_shipping_method_if_invalid(checkout_info, lines)
invalidate_checkout(checkout_info, lines, manager, save=True)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py b/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py
index f90202865d..d55f013361 100644
--- a/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py
+++ b/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py
@@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError
from graphql.error import GraphQLError
from ....checkout import models
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import (
@@ -109,9 +109,8 @@ class CheckoutRemovePromoCode(BaseMutation):
recalculate_discount=True,
save=True,
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py
index 7a140b9448..ac5a85de65 100644
--- a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py
@@ -5,7 +5,7 @@ import graphene
from django.core.exceptions import ValidationError
from ....checkout import AddressType, models
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import (
CheckoutLineInfo,
@@ -216,9 +216,8 @@ class CheckoutShippingAddressUpdate(AddressMetadataMixin, BaseMutation, I18nMixi
+ invalidate_prices_updated_fields
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py
index 6a04f4db7c..bb31ec51b1 100644
--- a/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py
@@ -3,7 +3,7 @@ from typing import Optional
import graphene
from django.core.exceptions import ValidationError
-from ....checkout.actions import call_checkout_event_for_checkout_info
+from ....checkout.actions import call_checkout_info_event
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import (
@@ -224,9 +224,8 @@ class CheckoutShippingMethodUpdate(BaseMutation):
)
get_checkout_metadata(checkout).save()
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
@@ -265,9 +264,8 @@ class CheckoutShippingMethodUpdate(BaseMutation):
+ invalidate_prices_updated_fields
)
get_checkout_metadata(checkout).save()
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
@@ -290,9 +288,8 @@ class CheckoutShippingMethodUpdate(BaseMutation):
)
get_checkout_metadata(checkout).save()
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines,
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py
index b12e869539..fb57e0a16c 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py
@@ -11,7 +11,7 @@ from django.utils import timezone
from prices import Money
from .....checkout import base_calculations, calculations
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.utils import add_variant_to_checkout, set_external_shipping_id
@@ -1543,8 +1543,8 @@ def test_with_active_problems_flow(
@patch(
- "saleor.graphql.checkout.mutations.checkout_add_promo_code.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_add_promo_code.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1554,7 +1554,7 @@ def test_with_active_problems_flow(
def test_checkout_add_voucher_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -1610,4 +1610,4 @@ def test_checkout_add_voucher_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py
index ba98b16b49..a83b2c7706 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_billing_address_update.py
@@ -4,7 +4,7 @@ from unittest.mock import call, patch
import pytest
from django.test import override_settings
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.utils import invalidate_checkout
from .....core.models import EventDelivery
from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
@@ -646,8 +646,8 @@ def test_checkout_billing_address_skip_validation_by_app(
@patch(
- "saleor.graphql.checkout.mutations.checkout_billing_address_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_billing_address_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -657,7 +657,7 @@ def test_checkout_billing_address_skip_validation_by_app(
def test_checkout_billing_address_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -718,4 +718,4 @@ def test_checkout_billing_address_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py
index 388faf6c69..69b4361dbb 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py
@@ -11,7 +11,7 @@ from django.utils import timezone
from .....channel.utils import DEPRECATION_WARNING_MESSAGE
from .....checkout import AddressType
-from .....checkout.actions import call_checkout_event_for_checkout
+from .....checkout.actions import call_checkout_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_lines
from .....checkout.models import Checkout
@@ -2648,8 +2648,8 @@ def test_checkout_create_skip_validation_billing_address_by_app(
@patch(
- "saleor.graphql.checkout.mutations.checkout_create.call_checkout_event_for_checkout",
- wraps=call_checkout_event_for_checkout,
+ "saleor.graphql.checkout.mutations.checkout_create.call_checkout_event",
+ wraps=call_checkout_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -2659,7 +2659,7 @@ def test_checkout_create_skip_validation_billing_address_by_app(
def test_checkout_create_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_event,
api_client,
stock,
graphql_address_data,
@@ -2731,4 +2731,4 @@ def test_checkout_create_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py
index b0a55e3cbc..586b7ac03b 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_attach.py
@@ -4,7 +4,7 @@ import graphene
from django.test import override_settings
from .....account.models import User
-from .....checkout.actions import call_checkout_event_for_checkout
+from .....checkout.actions import call_checkout_event
from .....checkout.error_codes import CheckoutErrorCode
from .....core.models import EventDelivery
from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
@@ -236,8 +236,8 @@ def test_with_active_problems_flow(user_api_client, checkout_with_problems):
@patch(
- "saleor.graphql.checkout.mutations.checkout_customer_attach.call_checkout_event_for_checkout",
- wraps=call_checkout_event_for_checkout,
+ "saleor.graphql.checkout.mutations.checkout_customer_attach.call_checkout_event",
+ wraps=call_checkout_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -247,7 +247,7 @@ def test_with_active_problems_flow(user_api_client, checkout_with_problems):
def test_checkout_customer_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -309,4 +309,4 @@ def test_checkout_customer_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py
index 52a3567176..341d887723 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_detach.py
@@ -3,7 +3,7 @@ from unittest.mock import call, patch
from django.test import override_settings
from .....account.models import User
-from .....checkout.actions import call_checkout_event_for_checkout
+from .....checkout.actions import call_checkout_event
from .....core.models import EventDelivery
from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from ....core.utils import to_global_id_or_none
@@ -115,8 +115,8 @@ def test_with_active_problems_flow(user_api_client, checkout_with_problems):
@patch(
- "saleor.graphql.checkout.mutations.checkout_customer_detach.call_checkout_event_for_checkout",
- wraps=call_checkout_event_for_checkout,
+ "saleor.graphql.checkout.mutations.checkout_customer_detach.call_checkout_event",
+ wraps=call_checkout_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -126,7 +126,7 @@ def test_with_active_problems_flow(user_api_client, checkout_with_problems):
def test_checkout_customer_detach_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -185,4 +185,4 @@ def test_checkout_customer_detach_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py
index 1f1d494bb7..1c7f125881 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_customer_note_update.py
@@ -2,7 +2,7 @@ from unittest.mock import call, patch
from django.test import override_settings
-from saleor.checkout.actions import call_checkout_event_for_checkout
+from saleor.checkout.actions import call_checkout_event
from saleor.core.models import EventDelivery
from saleor.webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
@@ -77,8 +77,8 @@ def test_with_active_problems_flow(api_client, checkout_with_problems):
@patch(
- "saleor.graphql.checkout.mutations.checkout_customer_note_update.call_checkout_event_for_checkout",
- wraps=call_checkout_event_for_checkout,
+ "saleor.graphql.checkout.mutations.checkout_customer_note_update.call_checkout_event",
+ wraps=call_checkout_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -88,7 +88,7 @@ def test_with_active_problems_flow(api_client, checkout_with_problems):
def test_checkout_customer_note_update_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -147,4 +147,4 @@ def test_checkout_customer_note_update_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
index d7b34621da..c8ab1422c9 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
@@ -6,7 +6,7 @@ import pytest
from django.test import override_settings
from .....account.models import Address
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.utils import PRIVATE_META_APP_SHIPPING_ID, invalidate_checkout
@@ -1009,8 +1009,8 @@ def test_checkout_delivery_method_update_from_cc_to_all_warehouses_disabled_cc(
@patch(
- "saleor.graphql.checkout.mutations.checkout_delivery_method_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_delivery_method_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1020,7 +1020,7 @@ def test_checkout_delivery_method_update_from_cc_to_all_warehouses_disabled_cc(
def test_checkout_delivery_method_update_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -1081,12 +1081,12 @@ def test_checkout_delivery_method_update_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
@patch(
- "saleor.graphql.checkout.mutations.checkout_delivery_method_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_delivery_method_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1096,7 +1096,7 @@ def test_checkout_delivery_method_update_triggers_webhooks(
def test_checkout_delivery_method_update_cc_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -1164,12 +1164,12 @@ def test_checkout_delivery_method_update_cc_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
@patch(
- "saleor.graphql.checkout.mutations.checkout_delivery_method_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_delivery_method_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1184,7 +1184,7 @@ def test_checkout_delivery_method_update_external_shipping_triggers_webhooks(
mock_clean_delivery,
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -1259,4 +1259,4 @@ def test_checkout_delivery_method_update_external_shipping_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py
index a34966feb3..f85a08c519 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_email_update.py
@@ -2,7 +2,7 @@ from unittest.mock import call, patch
from django.test import override_settings
-from .....checkout.actions import call_checkout_event_for_checkout
+from .....checkout.actions import call_checkout_event
from .....checkout.error_codes import CheckoutErrorCode
from .....core.models import EventDelivery
from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
@@ -88,8 +88,8 @@ def test_with_active_problems_flow(api_client, checkout_with_problems):
@patch(
- "saleor.graphql.checkout.mutations.checkout_email_update.call_checkout_event_for_checkout",
- wraps=call_checkout_event_for_checkout,
+ "saleor.graphql.checkout.mutations.checkout_email_update.call_checkout_event",
+ wraps=call_checkout_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -99,7 +99,7 @@ def test_with_active_problems_flow(api_client, checkout_with_problems):
def test_checkout_email_update_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -156,4 +156,4 @@ def test_checkout_email_update_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py
index 61e959b2d8..4af739d633 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_language_code_update.py
@@ -2,7 +2,7 @@ from unittest.mock import call, patch
from django.test import override_settings
-from .....checkout.actions import call_checkout_event_for_checkout
+from .....checkout.actions import call_checkout_event
from .....core.models import EventDelivery
from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from ....core.utils import to_global_id_or_none
@@ -71,8 +71,8 @@ def test_with_active_problems_flow(api_client, checkout_with_problems):
@patch(
- "saleor.graphql.checkout.mutations.checkout_language_code_update.call_checkout_event_for_checkout",
- wraps=call_checkout_event_for_checkout,
+ "saleor.graphql.checkout.mutations.checkout_language_code_update.call_checkout_event",
+ wraps=call_checkout_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -82,7 +82,7 @@ def test_with_active_problems_flow(api_client, checkout_with_problems):
def test_checkout_update_language_code_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -138,4 +138,4 @@ def test_checkout_update_language_code_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py
index 9cede21b29..5392fe98eb 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py
@@ -5,7 +5,7 @@ import graphene
from django.test import override_settings
from .....checkout import base_calculations
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.utils import (
@@ -206,8 +206,8 @@ def test_checkout_line_delete_non_removable_gift(user_api_client, checkout_line)
@patch(
- "saleor.graphql.checkout.mutations.checkout_line_delete.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_line_delete.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -217,7 +217,7 @@ def test_checkout_line_delete_non_removable_gift(user_api_client, checkout_line)
def test_checkout_line_delete_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -285,4 +285,4 @@ def test_checkout_line_delete_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py
index 3bf0c415be..f18ba02189 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py
@@ -10,7 +10,7 @@ from django.test import override_settings
from django.utils import timezone
from prices import Money
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.models import Checkout
@@ -1756,8 +1756,8 @@ def test_with_active_problems_flow(
@patch(
- "saleor.graphql.checkout.mutations.checkout_lines_add.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_lines_add.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1767,7 +1767,7 @@ def test_with_active_problems_flow(
def test_checkout_lines_add_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -1836,4 +1836,4 @@ def test_checkout_lines_add_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py
index d0d729b9f3..ab3e9d0ff8 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py
@@ -4,7 +4,7 @@ from unittest.mock import call, patch
import graphene
from django.test import override_settings
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.models import CheckoutLine
@@ -203,8 +203,8 @@ def test_checkout_lines_delete_not_associated_with_checkout(
@patch(
- "saleor.graphql.checkout.mutations.checkout_lines_delete.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_lines_delete.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -214,7 +214,7 @@ def test_checkout_lines_delete_not_associated_with_checkout(
def test_checkout_lines_delete_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -275,4 +275,4 @@ def test_checkout_lines_delete_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py
index 69a556da4a..07a06fdfce 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py
@@ -8,7 +8,7 @@ import pytest
from django.test import override_settings
from django.utils import timezone
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.models import Checkout, CheckoutLine
@@ -1363,8 +1363,8 @@ def test_checkout_lines_update_quantity_gift(user_api_client, checkout_with_item
@patch(
- "saleor.graphql.checkout.mutations.checkout_lines_add.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_lines_add.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1374,7 +1374,7 @@ def test_checkout_lines_update_quantity_gift(user_api_client, checkout_with_item
def test_checkout_lines_update_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -1440,4 +1440,4 @@ def test_checkout_lines_update_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py
index 5f4ad5181f..264e413683 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py
@@ -8,7 +8,7 @@ from django.utils import timezone
from prices import Money
from .....checkout import base_calculations
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....core.models import EventDelivery
@@ -708,8 +708,8 @@ def test_with_active_problems_flow(
@patch(
- "saleor.graphql.checkout.mutations.checkout_remove_promo_code.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_remove_promo_code.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -719,7 +719,7 @@ def test_with_active_problems_flow(
def test_checkout_remove_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -773,4 +773,4 @@ def test_checkout_remove_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py
index 9e52bf1f35..aa2ada5181 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py
@@ -6,7 +6,7 @@ import pytest
from django.test import override_settings
from django.utils import timezone
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.models import Checkout
@@ -1078,8 +1078,8 @@ def test_checkout_shipping_address_skip_validation_by_app(
@patch(
- "saleor.graphql.checkout.mutations.checkout_shipping_address_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_shipping_address_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -1089,7 +1089,7 @@ def test_checkout_shipping_address_skip_validation_by_app(
def test_checkout_shipping_address_update_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
user_api_client,
@@ -1150,4 +1150,4 @@ def test_checkout_shipping_address_update_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py
index 4dbc711e24..1b311ea348 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py
@@ -6,7 +6,7 @@ import pytest
from django.test import override_settings
from .....account.models import Address
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....checkout.error_codes import CheckoutErrorCode
from .....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from .....checkout.utils import PRIVATE_META_APP_SHIPPING_ID, invalidate_checkout
@@ -479,8 +479,8 @@ def test_with_active_problems_flow(
@patch(
- "saleor.graphql.checkout.mutations.checkout_shipping_method_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_shipping_method_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -490,7 +490,7 @@ def test_with_active_problems_flow(
def test_checkout_shipping_method_update_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
address,
@@ -552,12 +552,12 @@ def test_checkout_shipping_method_update_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
@patch(
- "saleor.graphql.checkout.mutations.checkout_shipping_method_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_shipping_method_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -567,7 +567,7 @@ def test_checkout_shipping_method_update_triggers_webhooks(
def test_checkout_shipping_method_update_external_shipping_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
address,
@@ -643,12 +643,12 @@ def test_checkout_shipping_method_update_external_shipping_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
@patch(
- "saleor.graphql.checkout.mutations.checkout_shipping_method_update.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.checkout.mutations.checkout_shipping_method_update.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -658,7 +658,7 @@ def test_checkout_shipping_method_update_external_shipping_triggers_webhooks(
def test_checkout_shipping_method_update_to_none_triggers_webhooks(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
address,
@@ -719,4 +719,4 @@ def test_checkout_shipping_method_update_to_none_triggers_webhooks(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/meta/extra_methods.py b/saleor/graphql/meta/extra_methods.py
index b59dd87f88..711021f011 100644
--- a/saleor/graphql/meta/extra_methods.py
+++ b/saleor/graphql/meta/extra_methods.py
@@ -1,4 +1,4 @@
-from ...checkout.actions import call_checkout_event_for_checkout_info
+from ...checkout.actions import call_checkout_info_event
from ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ...core.utils.events import webhook_async_event_requires_sync_webhooks_to_trigger
from ...order.actions import call_order_event
@@ -36,17 +36,15 @@ def extra_checkout_actions(instance, info: ResolveInfo, **data):
lines_info,
manager,
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager=manager,
- event_func=manager.checkout_updated,
event_name=WebhookEventAsyncType.CHECKOUT_UPDATED,
checkout_info=checkout_info,
lines=lines_info,
webhook_event_map=webhook_event_map,
)
- call_checkout_event_for_checkout_info(
+ call_checkout_info_event(
manager=manager,
- event_func=manager.checkout_metadata_updated,
event_name=WebhookEventAsyncType.CHECKOUT_METADATA_UPDATED,
checkout_info=checkout_info,
lines=lines_info,
@@ -81,7 +79,6 @@ def extra_order_actions(instance, info: ResolveInfo, **data):
manager = get_plugin_manager_promise(info.context).get()
call_order_event(
manager,
- manager.order_metadata_updated,
WebhookEventAsyncType.ORDER_METADATA_UPDATED,
instance,
)
diff --git a/saleor/graphql/meta/tests/mutations/test_checkout.py b/saleor/graphql/meta/tests/mutations/test_checkout.py
index b3a7ea1f72..72d9762fc8 100644
--- a/saleor/graphql/meta/tests/mutations/test_checkout.py
+++ b/saleor/graphql/meta/tests/mutations/test_checkout.py
@@ -6,7 +6,7 @@ from django.test import override_settings
from django.utils import timezone
from freezegun import freeze_time
-from .....checkout.actions import call_checkout_event_for_checkout_info
+from .....checkout.actions import call_checkout_info_event
from .....core.models import EventDelivery
from .....webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
from . import PRIVATE_KEY, PRIVATE_VALUE, PUBLIC_KEY, PUBLIC_VALUE
@@ -364,8 +364,8 @@ def test_update_public_metadata_for_checkout_line(api_client, checkout_line):
@freeze_time("2023-05-31 12:00:01")
@patch(
- "saleor.graphql.meta.extra_methods.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.meta.extra_methods.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -375,7 +375,7 @@ def test_update_public_metadata_for_checkout_line(api_client, checkout_line):
def test_add_metadata_for_checkout_triggers_webhooks_with_checkout_updated(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -429,13 +429,13 @@ def test_add_metadata_for_checkout_triggers_webhooks_with_checkout_updated(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
@freeze_time("2023-05-31 12:00:01")
@patch(
- "saleor.graphql.meta.extra_methods.call_checkout_event_for_checkout_info",
- wraps=call_checkout_event_for_checkout_info,
+ "saleor.graphql.meta.extra_methods.call_checkout_info_event",
+ wraps=call_checkout_info_event,
)
@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
@patch(
@@ -445,7 +445,7 @@ def test_add_metadata_for_checkout_triggers_webhooks_with_checkout_updated(
def test_add_metadata_for_checkout_triggers_webhooks_with_updated_metadata(
mocked_send_webhook_request_async,
mocked_send_webhook_request_sync,
- wrapped_call_checkout_event_for_checkout,
+ wrapped_call_checkout_info_event,
setup_checkout_webhooks,
settings,
api_client,
@@ -501,4 +501,4 @@ def test_add_metadata_for_checkout_triggers_webhooks_with_updated_metadata(
call(tax_delivery),
]
)
- assert wrapped_call_checkout_event_for_checkout.called
+ assert wrapped_call_checkout_info_event.called
diff --git a/saleor/graphql/order/mutations/draft_order_create.py b/saleor/graphql/order/mutations/draft_order_create.py
index 5eb31aab08..ea22354d07 100644
--- a/saleor/graphql/order/mutations/draft_order_create.py
+++ b/saleor/graphql/order/mutations/draft_order_create.py
@@ -595,14 +595,12 @@ class DraftOrderCreate(
if is_new_instance:
call_order_event(
manager,
- manager.draft_order_created,
WebhookEventAsyncType.DRAFT_ORDER_CREATED,
instance,
)
else:
call_order_event(
manager,
- manager.draft_order_updated,
WebhookEventAsyncType.DRAFT_ORDER_UPDATED,
instance,
)
diff --git a/saleor/graphql/order/mutations/draft_order_delete.py b/saleor/graphql/order/mutations/draft_order_delete.py
index d89d77e2b0..8d16dc67d4 100644
--- a/saleor/graphql/order/mutations/draft_order_delete.py
+++ b/saleor/graphql/order/mutations/draft_order_delete.py
@@ -58,7 +58,6 @@ class DraftOrderDelete(
response = super().perform_mutation(_root, info, **data)
call_order_event(
manager,
- manager.draft_order_deleted,
WebhookEventAsyncType.DRAFT_ORDER_DELETED,
order,
)
diff --git a/saleor/graphql/order/mutations/order_update.py b/saleor/graphql/order/mutations/order_update.py
index fafed8931a..6f40a82d8f 100644
--- a/saleor/graphql/order/mutations/order_update.py
+++ b/saleor/graphql/order/mutations/order_update.py
@@ -109,7 +109,6 @@ class OrderUpdate(DraftOrderCreate, ModelWithExtRefMutation):
instance.save()
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
instance,
)
diff --git a/saleor/graphql/order/mutations/order_update_shipping.py b/saleor/graphql/order/mutations/order_update_shipping.py
index 366021eb4c..11422ca5da 100644
--- a/saleor/graphql/order/mutations/order_update_shipping.py
+++ b/saleor/graphql/order/mutations/order_update_shipping.py
@@ -136,7 +136,5 @@ class OrderUpdateShipping(
order.save(update_fields=SHIPPING_METHOD_UPDATE_FIELDS)
# Post-process the results
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
return OrderUpdateShipping(order=order)
diff --git a/saleor/graphql/order/mutations/utils.py b/saleor/graphql/order/mutations/utils.py
index 5102460376..6b25fe1801 100644
--- a/saleor/graphql/order/mutations/utils.py
+++ b/saleor/graphql/order/mutations/utils.py
@@ -150,14 +150,11 @@ def call_event_by_order_status(order, manager):
if order.status == OrderStatus.DRAFT:
call_order_event(
manager,
- manager.draft_order_updated,
WebhookEventAsyncType.DRAFT_ORDER_UPDATED,
order,
)
else:
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
def try_payment_action(order, user, app, payment, func, *args, **kwargs):
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index 12c7ca5b99..03a6c4786f 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -3,7 +3,7 @@ from collections import defaultdict
from collections.abc import Iterable
from copy import deepcopy
from decimal import Decimal
-from typing import TYPE_CHECKING, Callable, Optional, TypedDict
+from typing import TYPE_CHECKING, Optional, TypedDict
from uuid import UUID
from django.conf import settings
@@ -31,6 +31,7 @@ from ..payment import (
from ..payment.interface import RefundData
from ..payment.models import Payment, Transaction, TransactionItem
from ..payment.utils import create_payment, create_transaction_for_order
+from ..plugins.manager import PluginsManager
from ..shipping.models import ShippingMethodChannelListing
from ..warehouse.management import (
deallocate_stock,
@@ -80,7 +81,6 @@ from .utils import (
if TYPE_CHECKING:
from ..app.models import App
- from ..plugins.manager import PluginsManager
from ..site.models import SiteSettings
from ..warehouse.models import Warehouse
from ..webhook.models import Webhook
@@ -140,16 +140,38 @@ WEBHOOK_EVENTS_FOR_ORDER_CREATED = {
WebhookEventAsyncType.ORDER_CREATED,
}.union(WEBHOOK_EVENTS_FOR_ORDER_CHARGED).union(WEBHOOK_EVENTS_FOR_ORDER_CONFIRMED)
+ORDER_WEBHOOK_EVENT_MAP = {
+ WebhookEventAsyncType.ORDER_CREATED: PluginsManager.order_created.__name__,
+ WebhookEventAsyncType.ORDER_UPDATED: PluginsManager.order_updated.__name__,
+ WebhookEventAsyncType.ORDER_REFUNDED: PluginsManager.order_refunded.__name__,
+ WebhookEventAsyncType.ORDER_CONFIRMED: PluginsManager.order_confirmed.__name__,
+ WebhookEventAsyncType.ORDER_CANCELLED: PluginsManager.order_cancelled.__name__,
+ WebhookEventAsyncType.ORDER_METADATA_UPDATED: PluginsManager.order_metadata_updated.__name__,
+ WebhookEventAsyncType.ORDER_FULLY_REFUNDED: PluginsManager.order_fully_refunded.__name__,
+ WebhookEventAsyncType.ORDER_FULLY_PAID: PluginsManager.order_fully_paid.__name__,
+ WebhookEventAsyncType.ORDER_PAID: PluginsManager.order_paid.__name__,
+ WebhookEventAsyncType.ORDER_FULFILLED: PluginsManager.order_fulfilled.__name__,
+ WebhookEventAsyncType.ORDER_EXPIRED: PluginsManager.order_expired.__name__,
+ WebhookEventAsyncType.DRAFT_ORDER_DELETED: PluginsManager.draft_order_deleted.__name__,
+ WebhookEventAsyncType.DRAFT_ORDER_CREATED: PluginsManager.draft_order_created.__name__,
+ WebhookEventAsyncType.DRAFT_ORDER_UPDATED: PluginsManager.draft_order_updated.__name__,
+}
+
def call_order_event(
manager: "PluginsManager",
- event_func: Callable,
event_name: str,
order: "Order",
database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,
webhook_event_map: Optional[dict[str, set["Webhook"]]] = None,
**event_kwargs,
):
+ if event_name not in ORDER_WEBHOOK_EVENT_MAP:
+ raise ValueError(f"Event {event_name} not found in ORDER_WEBHOOK_EVENT_MAP.")
+
+ plugin_manager_method_name = ORDER_WEBHOOK_EVENT_MAP[event_name]
+ event_func = getattr(manager, plugin_manager_method_name)
+
if order.status not in ORDER_EDITABLE_STATUS:
call_event_including_protected_events(event_func, order, **event_kwargs)
return
@@ -208,7 +230,6 @@ def order_created(
call_order_event(
manager,
- manager.order_created,
WebhookEventAsyncType.ORDER_CREATED,
order,
webhook_event_map=webhook_event_map,
@@ -257,7 +278,6 @@ def order_confirmed(
events.order_confirmed_event(order=order, user=user, app=app)
call_order_event(
manager,
- manager.order_confirmed,
WebhookEventAsyncType.ORDER_CONFIRMED,
order,
webhook_event_map=webhook_event_map,
@@ -298,14 +318,12 @@ def handle_fully_paid_order(
call_order_event(
manager,
- manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
webhook_event_map=webhook_event_map,
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -335,7 +353,6 @@ def cancel_order(
)
call_order_event(
manager,
- manager.order_cancelled,
WebhookEventAsyncType.ORDER_CANCELLED,
order,
webhook_event_map=webhook_event_map,
@@ -345,7 +362,6 @@ def cancel_order(
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -391,7 +407,6 @@ def order_refunded(
call_order_event(
manager,
- manager.order_refunded,
WebhookEventAsyncType.ORDER_REFUNDED,
order,
webhook_event_map=webhook_event_map,
@@ -399,7 +414,6 @@ def order_refunded(
if trigger_order_updated:
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -426,7 +440,6 @@ def order_refunded(
if total_refunded >= order.total.gross.amount:
call_order_event(
manager,
- manager.order_fully_refunded,
WebhookEventAsyncType.ORDER_FULLY_REFUNDED,
order,
webhook_event_map=webhook_event_map,
@@ -441,9 +454,7 @@ def order_voided(
manager: "PluginsManager",
):
events.payment_voided_event(order=order, user=user, app=app, payment=payment)
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
def order_returned(
@@ -491,7 +502,6 @@ def order_fulfilled(
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -502,7 +512,6 @@ def order_fulfilled(
if order.status == OrderStatus.FULFILLED:
call_order_event(
manager,
- manager.order_fulfilled,
WebhookEventAsyncType.ORDER_FULFILLED,
order,
webhook_event_map=webhook_event_map,
@@ -528,9 +537,7 @@ def order_awaits_fulfillment_approval(
events.fulfillment_awaits_approval_event(
order=order, user=user, app=app, fulfillment_lines=fulfillment_lines
)
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
def order_authorized(
@@ -547,7 +554,6 @@ def order_authorized(
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -577,7 +583,6 @@ def order_charged(
call_order_event(
manager,
- manager.order_paid,
WebhookEventAsyncType.ORDER_PAID,
order,
webhook_event_map=webhook_event_map,
@@ -595,7 +600,6 @@ def order_charged(
else:
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -668,7 +672,6 @@ def order_transaction_updated(
if order_updated:
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order_info.order,
webhook_event_map=webhook_event_map,
@@ -692,7 +695,6 @@ def fulfillment_tracking_updated(
call_event(manager.tracking_number_updated, fulfillment)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
fulfillment.order,
)
@@ -729,7 +731,6 @@ def cancel_fulfillment(
call_event(manager.fulfillment_canceled, fulfillment)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
fulfillment.order,
)
@@ -763,7 +764,6 @@ def cancel_waiting_fulfillment(
call_event(manager.fulfillment_canceled, fulfillment)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
fulfillment.order,
)
@@ -848,7 +848,6 @@ def approve_fulfillment(
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -857,7 +856,6 @@ def approve_fulfillment(
if order.status == OrderStatus.FULFILLED:
call_order_event(
manager,
- manager.order_fulfilled,
WebhookEventAsyncType.ORDER_FULFILLED,
order,
webhook_event_map=webhook_event_map,
@@ -906,13 +904,10 @@ def mark_order_as_paid_with_transaction(
)
call_order_event(
manager,
- manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
)
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
def mark_order_as_paid_with_payment(
@@ -971,14 +966,12 @@ def mark_order_as_paid_with_payment(
)
call_order_event(
manager,
- manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
webhook_event_map=webhook_event_map,
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -1534,9 +1527,7 @@ def create_refund_fulfillment(
FulfillmentStatus.WAITING_FOR_APPROVAL,
],
).delete()
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
return refunded_fulfillment
@@ -1900,9 +1891,7 @@ def create_fulfillments_for_returned_products(
],
).delete()
- call_order_event(
- manager, manager.order_updated, WebhookEventAsyncType.ORDER_UPDATED, order
- )
+ call_order_event(manager, WebhookEventAsyncType.ORDER_UPDATED, order)
return return_fulfillment, replace_fulfillment, new_order
diff --git a/saleor/order/tasks.py b/saleor/order/tasks.py
index 9ceeb9091c..84e37d7216 100644
--- a/saleor/order/tasks.py
+++ b/saleor/order/tasks.py
@@ -55,7 +55,6 @@ def send_order_updated(order_ids):
for order in Order.objects.filter(id__in=order_ids):
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -115,14 +114,12 @@ def _call_expired_order_events(order_ids, manager):
for order in orders:
call_order_event(
manager,
- manager.order_expired,
WebhookEventAsyncType.ORDER_EXPIRED,
order,
webhook_event_map=webhook_event_map,
)
call_order_event(
manager,
- manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
diff --git a/saleor/order/tests/test_order_actions.py b/saleor/order/tests/test_order_actions.py
index 18a8315084..e10b54aecb 100644
--- a/saleor/order/tests/test_order_actions.py
+++ b/saleor/order/tests/test_order_actions.py
@@ -484,14 +484,12 @@ def test_handle_fully_paid_order_triggers_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -750,7 +748,6 @@ def test_cancel_order_dont_trigger_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -760,7 +757,6 @@ def test_cancel_order_dont_trigger_webhooks(
),
call(
plugins_manager,
- plugins_manager.order_cancelled,
WebhookEventAsyncType.ORDER_CANCELLED,
order,
webhook_event_map=webhook_event_map,
@@ -949,21 +945,18 @@ def test_order_refunded_triggers_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_refunded,
WebhookEventAsyncType.ORDER_REFUNDED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_fully_refunded,
WebhookEventAsyncType.ORDER_FULLY_REFUNDED,
order,
webhook_event_map=webhook_event_map,
@@ -1048,7 +1041,6 @@ def test_order_voided_triggers_webhooks(
)
wrapped_call_order_event.assert_called_once_with(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
)
@@ -1145,14 +1137,12 @@ def test_order_fulfilled_dont_trigger_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
fulfilled_order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_fulfilled,
WebhookEventAsyncType.ORDER_FULFILLED,
fulfilled_order,
webhook_event_map=webhook_event_map,
@@ -1243,7 +1233,6 @@ def test_order_awaits_fulfillment_approval_triggers_webhooks(
)
wrapped_call_order_event.assert_called_once_with(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
fulfilled_order,
)
@@ -1328,7 +1317,6 @@ def test_order_authorized_triggers_webhooks(
)
wrapped_call_order_event.assert_called_once_with(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=None,
@@ -1439,14 +1427,12 @@ def test_order_charged_triggers_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_paid,
WebhookEventAsyncType.ORDER_PAID,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
webhook_event_map=webhook_event_map,
@@ -1815,21 +1801,18 @@ def test_order_transaction_updated_for_charged_triggers_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_paid,
WebhookEventAsyncType.ORDER_PAID,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
webhook_event_map=webhook_event_map,
@@ -1930,7 +1913,6 @@ def test_order_transaction_updated_for_authorized_triggers_webhooks(
wrapped_call_order_event.assert_called_once_with(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
@@ -2053,21 +2035,18 @@ def test_order_transaction_updated_for_refunded_triggers_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_refunded,
WebhookEventAsyncType.ORDER_REFUNDED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_fully_refunded,
WebhookEventAsyncType.ORDER_FULLY_REFUNDED,
order,
webhook_event_map=webhook_event_map,
@@ -2490,7 +2469,6 @@ def test_call_order_event_for_order_event_triggers_sync_webhook(
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- getattr(plugins_manager, webhook_event),
webhook_event,
order,
)
@@ -2518,6 +2496,47 @@ def test_call_order_event_for_order_event_triggers_sync_webhook(
)
+@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")
+@patch(
+ "saleor.webhook.transport.asynchronous.transport.send_webhook_request_async.apply_async"
+)
+@override_settings(PLUGINS=["saleor.plugins.webhook.plugin.WebhookPlugin"])
+def test_call_order_event_incorrect_webhook_event(
+ mocked_send_webhook_request_async,
+ mocked_send_webhook_request_sync,
+ setup_order_webhooks,
+ order_with_lines,
+ django_capture_on_commit_callbacks,
+):
+ # given
+ plugins_manager = get_plugins_manager(False)
+ order = order_with_lines
+ order.status = OrderStatus.UNCONFIRMED
+ order.should_refresh_prices = True
+ order.save(update_fields=["status", "should_refresh_prices"])
+
+ mocked_send_webhook_request_sync.return_value = []
+ setup_order_webhooks(WebhookEventAsyncType.ORDER_CREATED)
+
+ incorrect_event = WebhookEventAsyncType.CHECKOUT_UPDATED
+
+ # when
+ with django_capture_on_commit_callbacks(execute=True):
+ with pytest.raises(
+ ValueError,
+ match=f"Event {incorrect_event} not found in ORDER_WEBHOOK_EVENT_MAP.",
+ ):
+ call_order_event(
+ plugins_manager,
+ incorrect_event,
+ order,
+ )
+
+ # then
+ assert not mocked_send_webhook_request_async.called
+ assert not mocked_send_webhook_request_sync.called
+
+
@pytest.mark.parametrize(
"webhook_event",
[
@@ -2569,7 +2588,6 @@ def test_call_order_event_for_order_event_missing_filter_shipping_method_webhook
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- getattr(plugins_manager, webhook_event),
webhook_event,
order,
)
@@ -2646,7 +2664,6 @@ def test_call_order_event_for_order_event_skips_tax_webhook_when_prices_are_vali
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- getattr(plugins_manager, webhook_event),
webhook_event,
order,
)
@@ -2724,7 +2741,6 @@ def test_call_order_event_for_order_event_skips_sync_webhooks_when_order_not_edi
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- getattr(plugins_manager, webhook_event),
webhook_event,
order,
)
@@ -2778,7 +2794,6 @@ def test_call_order_event_for_order_event_skips_sync_webhooks_when_draft_order_d
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- plugins_manager.draft_order_deleted,
WebhookEventAsyncType.DRAFT_ORDER_DELETED,
order,
)
@@ -2833,7 +2848,6 @@ def test_call_order_event_for_order_event_skips_when_async_webhooks_missing(
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- plugins_manager.order_created,
WebhookEventAsyncType.ORDER_CREATED,
order,
)
@@ -2879,7 +2893,6 @@ def test_call_order_event_for_order_event_skips_when_sync_webhooks_missing(
with django_capture_on_commit_callbacks(execute=True):
call_order_event(
plugins_manager,
- plugins_manager.order_created,
WebhookEventAsyncType.ORDER_CREATED,
order,
)
@@ -3008,35 +3021,30 @@ def test_order_created_triggers_webhooks(
[
call(
plugins_manager,
- plugins_manager.order_created,
WebhookEventAsyncType.ORDER_CREATED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_confirmed,
WebhookEventAsyncType.ORDER_CONFIRMED,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_paid,
WebhookEventAsyncType.ORDER_PAID,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_fully_paid,
WebhookEventAsyncType.ORDER_FULLY_PAID,
order,
webhook_event_map=webhook_event_map,
),
call(
plugins_manager,
- plugins_manager.order_updated,
WebhookEventAsyncType.ORDER_UPDATED,
order,
webhook_event_map=webhook_event_map,