def test_cleaned_data(self): # Regression test (user, username, email) = self.create_dummy_user() data = {'email': email} form = PasswordResetForm(data) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['email'], email)
def test_nonexistant_email(self): # Test nonexistant email address data = {'email': '*****@*****.**'} form = PasswordResetForm(data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'email': [force_text(form.error_messages['unknown'])]})
def test_inactive_user(self): #tests that inactive user cannot #receive password reset email (user, username, email) = self.create_dummy_user() user.is_active = False user.save() form = PasswordResetForm({'email': email}) self.assertFalse(form.is_valid())
def test_unusable_password(self): user = User.objects.create_user('testuser', '*****@*****.**', 'test') data = {"email": "*****@*****.**"} form = PasswordResetForm(data) self.assertTrue(form.is_valid()) user.set_unusable_password() user.save() form = PasswordResetForm(data) self.assertFalse(form.is_valid()) self.assertEqual(form["email"].errors, [_("The user account associated with this e-mail address cannot reset the password.")])
def test_custom_email_subject(self): template_path = os.path.join(os.path.dirname(__file__), 'templates') with self.settings(TEMPLATE_DIRS=(template_path,)): data = {'email': '*****@*****.**'} form = PasswordResetForm(data) self.assertTrue(form.is_valid()) # Since we're not providing a request object, we must provide a # domain_override to prevent the save operation from failing in the # potential case where contrib.sites is not installed. Refs #16412. form.save(domain_override='example.com') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, 'Custom password reset on example.com')
def test_invalid_email(self): data = {'email': 'not valid'} form = PasswordResetForm(data) self.assertFalse(form.is_valid()) self.assertEqual(form['email'].errors, [force_text(EmailField.default_error_messages['invalid'])])