Good morning,
I would like to test that Django properly sends an e-mail for password reset as I have customised the routes. However I get a <HttpResponseForbidden status_code=403, "text/html">
and the e-mail is not implemented when I test it.
Here are the main features:
- url :
path('password_reset/', auth_views.PasswordResetView.as_view(template_name="customer/password_reset_form.html", email_template_name="customer/password_reset_e-mail.html", success_url="done/"),
- test method:
from django.contrib.auth import views as auth_views
from django.test import RequestFactory
from django.contrib.auth.models import AnonymousUser
class PasswordResetTest(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.user = User.objects.create_user(
username="user",
email="user@mail.com",
password="pwd")
def test_send_mail(self):
request = self.factory.post('/customer/password_reset', {'email': 'user@mail.com'})
response = auth_views.PasswordResetView.as_view()(request)
self.assertTemplateUsed('password_reset_e-mail.html')
print(response)
self.assertEqual(len(mail.outbox), 1)
Throught the print command, I can see an error 403 and that the outbox is empty. I just cannot find proper documentation to build a test on this very part of Django.
Thank you for your support.