Commit 142ec8b2 authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #8404 -- Isolated auth password-related tests from custom templates

parent ac4faa6d
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
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()