Sending E-Mail Unit Testing
See original GitHub issueI have written a function to send e-mail in Django. I have a written a unit test code in which i am over-riding the mail backend to in-memory django.core.mail.backends.locmem.EmailBackend
.
Not working when adding decorator:
@background(schedule=datetime.datetime.now())
def send_email_to_user(recipient_email, unique_code):
subject, from_email, to = 'Welcome', settings.DEFAULT_FROM_EMAIL, recipient_email
html_content = render_to_string('user/email/signup_link.html', {'code': unique_code})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
return True
And without decorator working fine in unit test.
def send_email_to_user(recipient_email, unique_code):
subject, from_email, to = 'Welcome', settings.DEFAULT_FROM_EMAIL, recipient_email
html_content = render_to_string('user/email/signup_link.html', {'code': unique_code})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
return True
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to unit test email sending? - Stack Overflow
If you need test sending e-mail only, you can configure your .config file like this <system.net> <mailSettings> <smtp ...
Read more >How to Unit Test Sending Emails - Synametrics Technologies
Using DevNullSmtp is an excellent way to test outbound emails. Messages sent to DevNullSmtp do not get delivered to any recipient. Instead, it...
Read more >How to unit test a mail sending function without ... - MSDN
In the init method of the unit test clear out the .eml files created using the two above properties. Send the email which...
Read more >How to test email sending? | Blog - Limilabs
nDumbster is a simple fake SMTP server designed especially to enable unit testing. 01. 02. 03. 04. 05. 06. 07. 08.
Read more >Unit Testing our Emails > Symfony Mailer - SymfonyCasts
Answer MailerTest . This generates a super simple unit test file: tests/MailerTest.php . ... The idea is that this will test the Mailer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@philippeowagner The Task runner is not executing from test database.
@philippeowagner already done its not working process_tasks not picking from test db.