summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-02-13 23:10:43 +0100
committerClaude Paroz <claude@2xlibre.net>2013-02-13 23:11:49 +0100
commit142ec8b2835c242339b930c47a70a3c7036df91d (patch)
tree7b91fd6a7a0363ad9996349f5fea1f95dfadaa26
parentac4faa6dc33407c93566884e53fa5d8ef44c0a2a (diff)
Fixed #8404 -- Isolated auth password-related tests from custom templates
-rw-r--r--django/contrib/auth/tests/views.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
index 6c508cf607..42bea825f5 100644
--- a/django/contrib/auth/tests/views.py
+++ b/django/contrib/auth/tests/views.py
@@ -1,3 +1,4 @@
+import itertools
import os
import re
@@ -49,8 +50,10 @@ class AuthViewsTestCase(TestCase):
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)
@skipIfCustomUser
@@ -87,7 +90,7 @@ class PasswordResetTest(AuthViewsTestCase):
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 @@ class PasswordResetTest(AuthViewsTestCase):
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 @@ class ChangePasswordTest(AuthViewsTestCase):
'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 @@ class ChangePasswordTest(AuthViewsTestCase):
'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 @@ class ChangePasswordTest(AuthViewsTestCase):
'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()