Skip to content

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

Wrap task function

akjanikd6cef2c32d53
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.py
index 0e450cb09f..c9de6fdfc1 100644
--- a/saleor/checkout/views/summary.py
+++ b/saleor/checkout/views/summary.py
@@ -6,7 +6,7 @@ from django.utils.translation import pgettext, pgettext_lazy
from ...account.forms import get_address_form
from ...account.models import Address
from ...core.exceptions import InsufficientStock
-from ...order.emails import send_order_confirmation
+from ...order.utils import order_send_confirmation
from ..forms import (
AnonymousUserBillingForm, BillingAddressesForm,
BillingWithoutShippingAddressForm, NoteForm)
@@ -28,7 +28,7 @@ def create_order(checkout):
order.history.create(
user=user, content=pgettext_lazy(
'Order status history entry', 'Order was placed'))
- send_order_confirmation.delay(order.pk)
+ order_send_confirmation(order.pk)
return order, redirect('order:payment', token=order.token)
diff --git a/saleor/order/signals.py b/saleor/order/signals.py
index 7926c58785..e0439e5eea 100644
--- a/saleor/order/signals.py
+++ b/saleor/order/signals.py
@@ -3,7 +3,7 @@ import logging
from django.utils.translation import pgettext_lazy
from ..core import analytics
-from .emails import send_order_confirmation
+from .utils import order_send_confirmation
logger = logging.getLogger(__name__)
@@ -15,7 +15,7 @@ def order_status_change(sender, instance, **kwargs):
order.history.create(
content=pgettext_lazy(
'Order status history entry', 'Order fully paid'))
- send_order_confirmation.delay(order.pk)
+ order_send_confirmation(order.pk)
try:
analytics.report_order(order.tracking_client_id, order)
except Exception:
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 0d11a6ef39..cb60cf3dcd 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -210,3 +210,8 @@ def move_order_line_to_group(line, target_group, quantity):
target_line.save()
line.quantity -= quantity
remove_empty_groups(line)
+
+
+def order_send_confirmation(order_pk):
+ from .emails import send_order_confirmation
+ send_order_confirmation.delay(order_pk)
diff --git a/tests/test_checkout_integration.py b/tests/test_checkout_integration.py
index d6678e5fe9..4e31864751 100644
--- a/tests/test_checkout_integration.py
+++ b/tests/test_checkout_integration.py
@@ -1,3 +1,5 @@
+from unittest.mock import patch
+
from django.urls import reverse
from payments import FraudStatus, PaymentStatus
@@ -6,7 +8,9 @@ from saleor.account.models import User
from .utils import get_redirect_location
-def test_checkout_flow(request_cart_with_item, client, shipping_method):
+@patch('saleor.checkout.views.summary.order_send_confirmation')
+def test_checkout_flow(
+ mock_send_confirmation, request_cart_with_item, client, shipping_method):
# Enter checkout
checkout_index = client.get(reverse('checkout:index'), follow=True)
# Checkout index redirects directly to shipping address step
@@ -65,6 +69,7 @@ def test_checkout_flow(request_cart_with_item, client, shipping_method):
order_password = reverse(
'order:checkout-success', kwargs={'token': order.token})
assert get_redirect_location(payment_response) == order_password
+ assert mock_send_confirmation.called_once_with(order.pk)
def test_checkout_flow_authenticated_user(