Skip to content

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

Test order fulfillment emails

Pacu206a937b15015
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index 5c90724f34..9268885124 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -50,6 +50,13 @@ def collect_data_for_email(order_pk, template):
'context': email_context, 'from_email': settings.ORDER_FROM_EMAIL}
+def collect_data_for_fullfillment_email(order_pk, template, fulfillment_pk):
+ fulfillment = Fulfillment.objects.get(pk=fulfillment_pk)
+ email_data = collect_data_for_email(order_pk, template)
+ email_data.update({'context': {'fulfillment': fulfillment}})
+ return email_data
+
+
@shared_task
def send_order_confirmation(order_pk):
"""Sends order confirmation email."""
@@ -59,18 +66,16 @@ def send_order_confirmation(order_pk):
@shared_task
def send_fulfillment_confirmation(order_pk, fulfillment_pk):
- email_data = collect_data_for_email(order_pk, CONFIRM_FULFILLMENT_TEMPLATE)
- fulfillment = Fulfillment.objects.get(pk=fulfillment_pk)
- email_data.update({'context': {'fulfillment': fulfillment}})
- _send_confirmation(**email_data)
+ email_data = collect_data_for_fullfillment_email(
+ order_pk, CONFIRM_FULFILLMENT_TEMPLATE, fulfillment_pk)
+ send_templated_mail(**email_data)
@shared_task
def send_fulfillment_update(order_pk, fulfillment_pk):
- email_data = collect_data_for_email(order_pk, UPDATE_FULFILLMENT_TEMPLATE)
- fulfillment = Fulfillment.objects.get(pk=fulfillment_pk)
- email_data.update({'context': {'fulfillment': fulfillment}})
- _send_confirmation(**email_data)
+ email_data = collect_data_for_fullfillment_email(
+ order_pk, UPDATE_FULFILLMENT_TEMPLATE, fulfillment_pk)
+ send_templated_mail(**email_data)
@shared_task
diff --git a/tests/test_emails.py b/tests/test_emails.py
index e1c9e0305c..2dad948455 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -33,6 +33,15 @@ def test_collect_data_for_order_confirmation_email(order):
assert 'schema_markup' in email_context
+def test_collect_data_for_fullfillment_email(fulfilled_order):
+ template = emails.CONFIRM_FULFILLMENT_TEMPLATE
+ fulfillment = fulfilled_order.fulfillments.first()
+ email_data = emails.collect_data_for_fullfillment_email(
+ fulfilled_order.pk, template, fulfillment.pk)
+ email_context = email_data['context']
+ assert email_context['fulfillment'] == fulfillment
+
+
def test_collect_data_for_email(order):
template = emails.CONFIRM_PAYMENT_TEMPLATE
email_data = emails.collect_data_for_email(order.pk, template)
@@ -50,9 +59,25 @@ def test_collect_data_for_email(order):
def test_send_emails(mocked_templated_email, order, template, send_email):
send_email(order.pk)
email_data = emails.collect_data_for_email(order.pk, template)
- email_context = email_data['context']
mocked_templated_email.assert_called_once_with(
recipient_list=[order.get_user_current_email()],
- context=email_context,
+ context=email_data['context'],
+ from_email=settings.ORDER_FROM_EMAIL,
+ template_name=template)
+
+
[email protected]('send_email,template', [
+ (emails.send_fulfillment_confirmation, emails.CONFIRM_FULFILLMENT_TEMPLATE), # noqa
+ (emails.send_fulfillment_update, emails.UPDATE_FULFILLMENT_TEMPLATE)])
[email protected]('saleor.order.emails.send_templated_mail')
+def test_send_fulfillment_emails(
+ mocked_templated_email, template, send_email, fulfilled_order):
+ fulfillment = fulfilled_order.fulfillments.first()
+ send_email(order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk)
+ email_data = emails.collect_data_for_fullfillment_email(
+ fulfilled_order.pk, template, fulfillment.pk)
+ mocked_templated_email.assert_called_once_with(
+ recipient_list=[fulfilled_order.get_user_current_email()],
+ context=email_data['context'],
from_email=settings.ORDER_FROM_EMAIL,
template_name=template)