Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #8404 -- Isolated auth password-related tests from custom templ…

…ates
  • Loading branch information...
commit 142ec8b2835c242339b930c47a70a3c7036df91d 1 parent ac4faa6
@claudep claudep authored
Showing with 10 additions and 7 deletions.
  1. +10 −7 django/contrib/auth/tests/views.py
View
17 django/contrib/auth/tests/views.py
@@ -1,3 +1,4 @@
+import itertools
import os
import re
@@ -49,8 +50,10 @@ def login(self, password='password'):
self.assertTrue(response.url.endswith(settings.LOGIN_REDIRECT_URL))
self.assertTrue(SESSION_KEY in self.client.session)
- def assertContainsEscaped(self, response, text, **kwargs):
- return self.assertContains(response, escape(force_text(text)), **kwargs)
+ def assertFormError(self, response, error):
+ """Assert that error is found in response.context['form'] errors"""
+ form_errors = list(itertools.chain(*response.context['form'].errors.values()))
+ self.assertIn(force_text(text), form_errors)
@aaugustin Owner

text isn't defined here.

@claudep Collaborator
claudep added a note

Doh... Sorry :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@skipIfCustomUser
@@ -87,7 +90,7 @@ def test_email_not_found(self):
response = self.client.get('/password_reset/')
self.assertEqual(response.status_code, 200)
response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'})
- self.assertContainsEscaped(response, PasswordResetForm.error_messages['unknown'])
+ self.assertFormError(response, PasswordResetForm.error_messages['unknown'])
self.assertEqual(len(mail.outbox), 0)
def test_email_found(self):
@@ -214,7 +217,7 @@ def test_confirm_different_passwords(self):
url, path = self._test_confirm_start()
response = self.client.post(path, {'new_password1': 'anewpassword',
'new_password2': 'x'})
- self.assertContainsEscaped(response, SetPasswordForm.error_messages['password_mismatch'])
+ self.assertFormError(response, SetPasswordForm.error_messages['password_mismatch'])
@override_settings(AUTH_USER_MODEL='auth.CustomUser')
@@ -248,7 +251,7 @@ def fail_login(self, password='password'):
'username': 'testclient',
'password': password,
})
- self.assertContainsEscaped(response, AuthenticationForm.error_messages['invalid_login'] % {
+ self.assertFormError(response, AuthenticationForm.error_messages['invalid_login'] % {
'username': User._meta.get_field('username').verbose_name
})
@@ -262,7 +265,7 @@ def test_password_change_fails_with_invalid_old_password(self):
'new_password1': 'password1',
'new_password2': 'password1',
})
- self.assertContainsEscaped(response, PasswordChangeForm.error_messages['password_incorrect'])
+ self.assertFormError(response, PasswordChangeForm.error_messages['password_incorrect'])
def test_password_change_fails_with_mismatched_passwords(self):
self.login()
@@ -271,7 +274,7 @@ def test_password_change_fails_with_mismatched_passwords(self):
'new_password1': 'password1',
'new_password2': 'donuts',
})
- self.assertContainsEscaped(response, SetPasswordForm.error_messages['password_mismatch'])
+ self.assertFormError(response, SetPasswordForm.error_messages['password_mismatch'])
def test_password_change_succeeds(self):
self.login()
Please sign in to comment.
Something went wrong with that request. Please try again.