Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make celery tasks from email sending proxy functions
Jakub Draganekc0c20eb9a8e3
diff --git a/saleor/order/emails.py b/saleor/order/emails.pyindex a78db590be..76b877aa24 100644--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@ -1,6 +1,7 @@from templated_email import send_templated_mailfrom ..site.utils import get_site_namefrom django.conf import settings+from celery import shared_taskCONFIRM_ORDER_TEMPLATE = 'order/confirm_order'@@ -15,9 +16,11 @@ def __send_confirmation(address, url, template):template_name=template)+@shared_taskdef send_order_confirmation(address, url):__send_confirmation(address, url, CONFIRM_ORDER_TEMPLATE)+@shared_taskdef 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.pyindex bdc25a3fb8..6dacac87cc 100644--- a/tests/test_asynchronous_tasks.py+++ b/tests/test_asynchronous_tasks.py@@ -2,6 +2,9 @@ from __future__ import unicode_literalsimport celeryimport 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.integrationdef 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.pyindex 9ad43d9879..83868d52ea 100644--- a/tests/test_emails.py+++ b/tests/test_emails.py@@ -2,7 +2,6 @@ from __future__ import unicode_literalsfrom django.conf import settingsimport saleor.order.emails as emails-import pytestimport 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)+