-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZDL-96: Integrate Django RQ for asynchronous processing
- Loading branch information
1 parent
74d09c3
commit beef8da
Showing
11 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
web: gunicorn zadalaAPI.wsgi | ||
web: gunicorn zadalaAPI.wsgi | ||
|
||
worker: python manage.py rqworker high default low |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Dict | ||
|
||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
from django.template.loader import render_to_string | ||
from django.utils.html import strip_tags | ||
from validate_email import validate_email | ||
|
||
|
||
def send_email_notification( | ||
customer_email: str, template: str, subject: str, context_data: Dict | ||
): | ||
if validate_email(email_address=customer_email, check_smtp=False): | ||
html_message = render_to_string(template, context_data) | ||
plain_message = strip_tags(html_message) | ||
|
||
send_mail( | ||
subject, | ||
plain_message, | ||
settings.EMAIL_HOST_USER, | ||
[customer_email, settings.EMAIL_HOST_USER], | ||
fail_silently=False, | ||
html_message=html_message, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from unittest.mock import patch | ||
|
||
from orders.tasks import send_email_notification | ||
|
||
|
||
@patch("django.core.mail.send_mail", lambda **kwargs: kwargs) | ||
@patch("validate_email.validate_email", lambda z, x: x) | ||
def test_send_email_notification_task(): | ||
""" | ||
Test sending of email task | ||
""" | ||
send_email_notification( | ||
"[email protected]", | ||
"invoice_email_template.html", | ||
"subject", | ||
{"context": None}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters