question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending E-Mail Unit Testing

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mukulmantoshcommented, Feb 4, 2019

@philippeowagner The Task runner is not executing from test database.

0reactions
mukulmantoshcommented, Feb 4, 2019

@philippeowagner already done its not working process_tasks not picking from test db.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found