Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def test_invalid_email(self):
     data = {'email': 'not valid'}
     form = PasswordResetForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form['email'].errors,
         [force_unicode(EmailField.default_error_messages['invalid'])])
Ejemplo n.º 4
0
 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_unicode(form.error_messages['unknown'])]})
Ejemplo n.º 5
0
 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())
Ejemplo n.º 6
0
 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_unicode(form.error_messages['unknown'])]})
Ejemplo n.º 7
0
 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())
Ejemplo n.º 8
0
 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,
                      [_(u"The user account associated with this e-mail address cannot reset the password.")])
Ejemplo n.º 9
0
 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, u'Custom password reset on example.com')
Ejemplo n.º 10
0
 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,
                          u'Custom password reset on example.com')
Ejemplo n.º 11
0
 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, [
         _(u"The user account associated with this e-mail address cannot reset the password."
           )
     ])
Ejemplo n.º 12
0
 def test_invalid_email(self):
     data = {'email': 'not valid'}
     form = PasswordResetForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form['email'].errors,
                      [force_unicode(EmailField.default_error_messages['invalid'])])