[Answer]-Django: Testing auto-generated (error) emails

1๐Ÿ‘

โœ…

I found the answer to your problem at this line, in the django code:
https://github.com/django/django/blob/stable/1.5.x/django/middleware/common.py#L114

Apparently the request must have HTTP_REFERER set for the email to be sent. This should fix your text:

class BadLinkEmailTest(TestCase):

    def setUp(self):
        self.client.login(username='user', password='pass')

    def test_for_bad_link_email_sent(self):
        extra = {
            'HTTP_REFERER': 'http://somesite.com/'
        }
        response = self.client.get('/jibberish/', **extra)
        self.assertEqual(int(response.status_code), 404)
        self.assertEqual(len(mail.outbox), 1)

Leave a comment