Ticket #17247: fix-auth-tests-localization.diff

File fix-auth-tests-localization.diff, 11.9 KB (added by rabio, 13 years ago)
  • django/contrib/auth/tests/forms.py

    diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
    index 429967c..1cac710 100644
    a b from django.core import mail  
    44from django.contrib.auth.models import User
    55from django.contrib.auth.forms import UserCreationForm, AuthenticationForm,  PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm
    66from django.test import TestCase
    7 
     7from django.utils.translation import ugettext as _
    88
    99class UserCreationFormTest(TestCase):
    1010
    class UserCreationFormTest(TestCase):  
    1919        form = UserCreationForm(data)
    2020        self.assertFalse(form.is_valid())
    2121        self.assertEqual(form["username"].errors,
    22                          [u'A user with that username already exists.'])
     22                         [_(u'A user with that username already exists.')])
    2323
    2424    def test_invalid_data(self):
    2525        data = {
    class UserCreationFormTest(TestCase):  
    3030        form = UserCreationForm(data)
    3131        self.assertFalse(form.is_valid())
    3232        self.assertEqual(form["username"].errors,
    33                          [u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
     33                         [_(u'This value may contain only letters, numbers and @/./+/-/_ characters.')])
    3434
    3535
    3636    def test_password_verification(self):
    class UserCreationFormTest(TestCase):  
    4343        form = UserCreationForm(data)
    4444        self.assertFalse(form.is_valid())
    4545        self.assertEqual(form["password2"].errors,
    46                          [u"The two password fields didn't match."])
     46                         [_(u"The two password fields didn't match.")])
    4747
    4848
    4949    def test_both_passwords(self):
    class UserCreationFormTest(TestCase):  
    5252        form = UserCreationForm(data)
    5353        self.assertFalse(form.is_valid())
    5454        self.assertEqual(form['password1'].errors,
    55                          [u'This field is required.'])
     55                         [_(u'This field is required.')])
    5656        self.assertEqual(form['password2'].errors,
    57                          [u'This field is required.'])
     57                         [_(u'This field is required.')])
    5858
    5959
    6060        data['password2'] = 'test123'
    6161        form = UserCreationForm(data)
    6262        self.assertFalse(form.is_valid())
    6363        self.assertEqual(form['password1'].errors,
    64                          [u'This field is required.'])
     64                         [_(u'This field is required.')])
    6565
    6666    def test_success(self):
    6767        # The success case.
    class AuthenticationFormTest(TestCase):  
    9191        form = AuthenticationForm(None, data)
    9292        self.assertFalse(form.is_valid())
    9393        self.assertEqual(form.non_field_errors(),
    94                          [u'Please enter a correct username and password. Note that both fields are case-sensitive.'])
     94                         [_(u'Please enter a correct username and password. Note that both fields are case-sensitive.')])
    9595
    9696    def test_inactive_user(self):
    9797        # The user is inactive.
    class AuthenticationFormTest(TestCase):  
    102102        form = AuthenticationForm(None, data)
    103103        self.assertFalse(form.is_valid())
    104104        self.assertEqual(form.non_field_errors(),
    105                          [u'This account is inactive.'])
     105                         [_(u'This account is inactive.')])
    106106
    107107
    108108    def test_success(self):
    class SetPasswordFormTest(TestCase):  
    130130        form = SetPasswordForm(user, data)
    131131        self.assertFalse(form.is_valid())
    132132        self.assertEqual(form["new_password2"].errors,
    133                          [u"The two password fields didn't match."])
     133                         [_(u"The two password fields didn't match.")])
    134134
    135135    def test_success(self):
    136136        user = User.objects.get(username='testclient')
    class PasswordChangeFormTest(TestCase):  
    156156        form = PasswordChangeForm(user, data)
    157157        self.assertFalse(form.is_valid())
    158158        self.assertEqual(form["old_password"].errors,
    159                          [u'Your old password was entered incorrectly. Please enter it again.'])
     159                         [_(u'Your old password was entered incorrectly. Please enter it again.')])
    160160
    161161
    162162    def test_password_verification(self):
    class PasswordChangeFormTest(TestCase):  
    170170        form = PasswordChangeForm(user, data)
    171171        self.assertFalse(form.is_valid())
    172172        self.assertEqual(form["new_password2"].errors,
    173                          [u"The two password fields didn't match."])
     173                         [_(u"The two password fields didn't match.")])
    174174
    175175
    176176    def test_success(self):
    class UserChangeFormTest(TestCase):  
    200200        form = UserChangeForm(data, instance=user)
    201201        self.assertFalse(form.is_valid())
    202202        self.assertEqual(form['username'].errors,
    203                          [u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
     203                         [_(u'This value may contain only letters, numbers and @/./+/-/_ characters.')])
    204204
    205205    def test_bug_14242(self):
    206206        # A regression test, introduce by adding an optimization for the
    class PasswordResetFormTest(TestCase):  
    236236        form = PasswordResetForm(data)
    237237        self.assertFalse(form.is_valid())
    238238        self.assertEqual(form['email'].errors,
    239                          [u'Enter a valid e-mail address.'])
     239                         [_(u'Enter a valid e-mail address.')])
    240240
    241241    def test_nonexistant_email(self):
    242242        # Test nonexistant email address
    class PasswordResetFormTest(TestCase):  
    244244        form = PasswordResetForm(data)
    245245        self.assertFalse(form.is_valid())
    246246        self.assertEqual(form.errors,
    247                          {'email': [u"That e-mail address doesn't have an associated user account. Are you sure you've registered?"]})
     247                         {'email': [_(u"That e-mail address doesn't have an associated user account. Are you sure you've registered?")]})
    248248
    249249    def test_cleaned_data(self):
    250250        # Regression test
    class PasswordResetFormTest(TestCase):  
    295295        form = PasswordResetForm(data)
    296296        self.assertFalse(form.is_valid())
    297297        self.assertEqual(form["email"].errors,
    298                          [u"The user account associated with this e-mail address cannot reset the password."])
     298                         [_(u"The user account associated with this e-mail address cannot reset the password.")])
  • django/contrib/auth/tests/views.py

    diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
    index 9fccb3e..2ea7b01 100644
    a b from django.test import TestCase  
    1313from django.core import mail
    1414from django.core.urlresolvers import reverse
    1515from django.http import QueryDict
     16from django.utils.translation import ugettext as _
    1617
    1718
    1819class AuthViewsTestCase(TestCase):
    class AuthViewsTestCase(TestCase):  
    4748        self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))
    4849        self.assertTrue(SESSION_KEY in self.client.session)
    4950
     51    def _(self, text):
     52        escape = (('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;'),
     53                  ("'", '&#39;'), ('"', '&quot;'))
     54        return reduce(lambda x, y: x.replace(*y), escape, _(text).encode('utf-8'))
    5055
    5156class AuthViewNamedURLTests(AuthViewsTestCase):
    5257    urls = 'django.contrib.auth.urls'
    class PasswordResetTest(AuthViewsTestCase):  
    8085        response = self.client.get('/password_reset/')
    8186        self.assertEqual(response.status_code, 200)
    8287        response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'})
    83         self.assertContains(response, "That e-mail address doesn&#39;t have an associated user account")
     88        self.assertContains(response, self._("That e-mail address doesn't have an associated user account. Are you sure you've registered?"))
    8489        self.assertEqual(len(mail.outbox), 0)
    8590
    8691    def test_email_found(self):
    class PasswordResetTest(AuthViewsTestCase):  
    115120        response = self.client.get(path)
    116121        # redirect to a 'complete' page:
    117122        self.assertEqual(response.status_code, 200)
    118         self.assertTrue("Please enter your new password" in response.content)
     123        self.assertTrue(self._(u"Please enter your new password") in response.content)
    119124
    120125    def test_confirm_invalid(self):
    121126        url, path = self._test_confirm_start()
    class PasswordResetTest(AuthViewsTestCase):  
    125130
    126131        response = self.client.get(path)
    127132        self.assertEqual(response.status_code, 200)
    128         self.assertTrue("The password reset link was invalid" in response.content)
     133        self.assertTrue(self._(u"The password reset link was invalid") in response.content)
    129134
    130135    def test_confirm_invalid_user(self):
    131136        # Ensure that we get a 200 response for a non-existant user, not a 404
    132137        response = self.client.get('/reset/123456-1-1/')
    133138        self.assertEqual(response.status_code, 200)
    134         self.assertTrue("The password reset link was invalid" in response.content)
     139        self.assertTrue(self._(u"The password reset link was invalid") in response.content)
    135140
    136141    def test_confirm_overflow_user(self):
    137142        # Ensure that we get a 200 response for a base36 user id that overflows int
    138143        response = self.client.get('/reset/zzzzzzzzzzzzz-1-1/')
    139144        self.assertEqual(response.status_code, 200)
    140         self.assertTrue("The password reset link was invalid" in response.content)
     145        self.assertTrue(self._(u"The password reset link was invalid") in response.content)
    141146
    142147    def test_confirm_invalid_post(self):
    143148        # Same as test_confirm_invalid, but trying
    class PasswordResetTest(AuthViewsTestCase):  
    164169        # Check we can't use the link again
    165170        response = self.client.get(path)
    166171        self.assertEqual(response.status_code, 200)
    167         self.assertTrue("The password reset link was invalid" in response.content)
     172        self.assertTrue(self._(u"The password reset link was invalid") in response.content)
    168173
    169174    def test_confirm_different_passwords(self):
    170175        url, path = self._test_confirm_start()
    171176        response = self.client.post(path, {'new_password1': 'anewpassword',
    172177                                           'new_password2':' x'})
    173178        self.assertEqual(response.status_code, 200)
    174         self.assertTrue("The two password fields didn&#39;t match" in response.content)
     179        self.assertTrue(self._(u"The two password fields didn't match.") in response.content)
    175180
    176181class ChangePasswordTest(AuthViewsTestCase):
    177182
    class ChangePasswordTest(AuthViewsTestCase):  
    182187            }
    183188        )
    184189        self.assertEqual(response.status_code, 200)
    185         self.assertTrue("Please enter a correct username and password. Note that both fields are case-sensitive." in response.content)
     190        self.assertTrue(self._(u"Please enter a correct username and password. Note that both fields are case-sensitive.") in response.content)
    186191
    187192    def logout(self):
    188193        response = self.client.get('/logout/')
    class ChangePasswordTest(AuthViewsTestCase):  
    196201            }
    197202        )
    198203        self.assertEqual(response.status_code, 200)
    199         self.assertTrue("Your old password was entered incorrectly. Please enter it again." in response.content)
     204        self.assertTrue(self._(u"Your old password was entered incorrectly. Please enter it again.") in response.content)
    200205
    201206    def test_password_change_fails_with_mismatched_passwords(self):
    202207        self.login()
    class ChangePasswordTest(AuthViewsTestCase):  
    207212            }
    208213        )
    209214        self.assertEqual(response.status_code, 200)
    210         self.assertTrue("The two password fields didn&#39;t match." in response.content)
     215        self.assertTrue(self._(u"The two password fields didn't match.") in response.content)
    211216
    212217    def test_password_change_succeeds(self):
    213218        self.login()
Back to Top