I use the Django 5.0.1 with django-allauth. With real smtp email backend, email confirmation works. Django's email testing features are also working if django-allauth is not involved, like in the example of the Django testing docs' email service.
As soon as I want to test the third party django-allauth confirmation email sending function, the mail.outbox does not have any item.
My partial test code:
class SignupProcessTest(TestCase):
def setUp(self):
# We setup base form data and we overwrite only test method specific ones
self.data = {"email": "[email protected]",
"password1": "ajtoablak1",
"newsletter": 1}
def test_confirmEmailSent(self):
self.client.post(reverse("account_signup"),
self.data,
secure=True,
follow=True)
# check email
self.assertEqual(len(mail.outbox), 1, f"Email was not sent for confirmation:{len(mail.outbox)}")
Based on the docs Django just replaces transparently the email backend settings and collects all emails to the mail.outbox array. Even Django-allauth should not be aware which email backend serves its email sending request.
When I try this in my local server, after signup I am redirected to another page and I get an email within seconds. Why does not it happen in test environment?
Any idea?
Try using APITransactionTestCase instead of TestCase. Maybe it helps...