Skip to content

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

Make celery tasks from email sending proxy functions

Jakub Draganekc0c20eb9a8e3
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index a78db590be..76b877aa24 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -1,6 +1,7 @@
from templated_email import send_templated_mail
from ..site.utils import get_site_name
from django.conf import settings
+from celery import shared_task
CONFIRM_ORDER_TEMPLATE = 'order/confirm_order'
@@ -15,9 +16,11 @@ def __send_confirmation(address, url, template):
template_name=template)
+@shared_task
def send_order_confirmation(address, url):
__send_confirmation(address, url, CONFIRM_ORDER_TEMPLATE)
+@shared_task
def send_payment_confirmation(address, url):
__send_confirmation(address, url, CONFIRM_PAYMENT_TEMPLATE)
diff --git a/tests/test_asynchronous_tasks.py b/tests/test_asynchronous_tasks.py
index bdc25a3fb8..6dacac87cc 100644
--- a/tests/test_asynchronous_tasks.py
+++ b/tests/test_asynchronous_tasks.py
@@ -2,6 +2,9 @@ from __future__ import unicode_literals
import celery
import pytest
+import mock
+from saleor.order.emails import (send_order_confirmation,
+ send_payment_confirmation)
@celery.shared_task
@@ -12,3 +15,13 @@ def dummy_task(x):
@pytest.mark.integration
def test_task_running_asynchronously_on_worker(celery_worker):
assert dummy_task.delay(42).get(timeout=10) == 43
+
+
[email protected]('saleor.order.emails.send_templated_mail')
+def test_email_sending_asynchronously(email_send, celery_app, celery_worker):
+ order = send_order_confirmation.delay('[email protected]', '/nowhere/to/go')
+ payment = send_payment_confirmation.delay('[email protected]', '/nowhere/to/go')
+ order.get()
+ payment.get()
diff --git a/tests/test_emails.py b/tests/test_emails.py
index 9ad43d9879..83868d52ea 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
from django.conf import settings
import saleor.order.emails as emails
-import pytest
import mock
@@ -32,3 +31,4 @@ def test_send_order_payment_confirmation(mocked_templated_email,
mocked_templated_email.assert_called_once_with(
recipient_list=[EMAIL], context=context, from_email=EMAIL_FROM,
template_name=emails.CONFIRM_PAYMENT_TEMPLATE)
+