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)
Source:stackexchange.com