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
|
4 | 4 | from django.contrib.auth.models import User |
5 | 5 | from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm |
6 | 6 | from django.test import TestCase |
7 | | |
| 7 | from django.utils.translation import ugettext as _ |
8 | 8 | |
9 | 9 | class UserCreationFormTest(TestCase): |
10 | 10 | |
… |
… |
class UserCreationFormTest(TestCase):
|
19 | 19 | form = UserCreationForm(data) |
20 | 20 | self.assertFalse(form.is_valid()) |
21 | 21 | self.assertEqual(form["username"].errors, |
22 | | [u'A user with that username already exists.']) |
| 22 | [_(u'A user with that username already exists.')]) |
23 | 23 | |
24 | 24 | def test_invalid_data(self): |
25 | 25 | data = { |
… |
… |
class UserCreationFormTest(TestCase):
|
30 | 30 | form = UserCreationForm(data) |
31 | 31 | self.assertFalse(form.is_valid()) |
32 | 32 | 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.')]) |
34 | 34 | |
35 | 35 | |
36 | 36 | def test_password_verification(self): |
… |
… |
class UserCreationFormTest(TestCase):
|
43 | 43 | form = UserCreationForm(data) |
44 | 44 | self.assertFalse(form.is_valid()) |
45 | 45 | self.assertEqual(form["password2"].errors, |
46 | | [u"The two password fields didn't match."]) |
| 46 | [_(u"The two password fields didn't match.")]) |
47 | 47 | |
48 | 48 | |
49 | 49 | def test_both_passwords(self): |
… |
… |
class UserCreationFormTest(TestCase):
|
52 | 52 | form = UserCreationForm(data) |
53 | 53 | self.assertFalse(form.is_valid()) |
54 | 54 | self.assertEqual(form['password1'].errors, |
55 | | [u'This field is required.']) |
| 55 | [_(u'This field is required.')]) |
56 | 56 | self.assertEqual(form['password2'].errors, |
57 | | [u'This field is required.']) |
| 57 | [_(u'This field is required.')]) |
58 | 58 | |
59 | 59 | |
60 | 60 | data['password2'] = 'test123' |
61 | 61 | form = UserCreationForm(data) |
62 | 62 | self.assertFalse(form.is_valid()) |
63 | 63 | self.assertEqual(form['password1'].errors, |
64 | | [u'This field is required.']) |
| 64 | [_(u'This field is required.')]) |
65 | 65 | |
66 | 66 | def test_success(self): |
67 | 67 | # The success case. |
… |
… |
class AuthenticationFormTest(TestCase):
|
91 | 91 | form = AuthenticationForm(None, data) |
92 | 92 | self.assertFalse(form.is_valid()) |
93 | 93 | 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.')]) |
95 | 95 | |
96 | 96 | def test_inactive_user(self): |
97 | 97 | # The user is inactive. |
… |
… |
class AuthenticationFormTest(TestCase):
|
102 | 102 | form = AuthenticationForm(None, data) |
103 | 103 | self.assertFalse(form.is_valid()) |
104 | 104 | self.assertEqual(form.non_field_errors(), |
105 | | [u'This account is inactive.']) |
| 105 | [_(u'This account is inactive.')]) |
106 | 106 | |
107 | 107 | |
108 | 108 | def test_success(self): |
… |
… |
class SetPasswordFormTest(TestCase):
|
130 | 130 | form = SetPasswordForm(user, data) |
131 | 131 | self.assertFalse(form.is_valid()) |
132 | 132 | self.assertEqual(form["new_password2"].errors, |
133 | | [u"The two password fields didn't match."]) |
| 133 | [_(u"The two password fields didn't match.")]) |
134 | 134 | |
135 | 135 | def test_success(self): |
136 | 136 | user = User.objects.get(username='testclient') |
… |
… |
class PasswordChangeFormTest(TestCase):
|
156 | 156 | form = PasswordChangeForm(user, data) |
157 | 157 | self.assertFalse(form.is_valid()) |
158 | 158 | 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.')]) |
160 | 160 | |
161 | 161 | |
162 | 162 | def test_password_verification(self): |
… |
… |
class PasswordChangeFormTest(TestCase):
|
170 | 170 | form = PasswordChangeForm(user, data) |
171 | 171 | self.assertFalse(form.is_valid()) |
172 | 172 | self.assertEqual(form["new_password2"].errors, |
173 | | [u"The two password fields didn't match."]) |
| 173 | [_(u"The two password fields didn't match.")]) |
174 | 174 | |
175 | 175 | |
176 | 176 | def test_success(self): |
… |
… |
class UserChangeFormTest(TestCase):
|
200 | 200 | form = UserChangeForm(data, instance=user) |
201 | 201 | self.assertFalse(form.is_valid()) |
202 | 202 | 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.')]) |
204 | 204 | |
205 | 205 | def test_bug_14242(self): |
206 | 206 | # A regression test, introduce by adding an optimization for the |
… |
… |
class PasswordResetFormTest(TestCase):
|
236 | 236 | form = PasswordResetForm(data) |
237 | 237 | self.assertFalse(form.is_valid()) |
238 | 238 | self.assertEqual(form['email'].errors, |
239 | | [u'Enter a valid e-mail address.']) |
| 239 | [_(u'Enter a valid e-mail address.')]) |
240 | 240 | |
241 | 241 | def test_nonexistant_email(self): |
242 | 242 | # Test nonexistant email address |
… |
… |
class PasswordResetFormTest(TestCase):
|
244 | 244 | form = PasswordResetForm(data) |
245 | 245 | self.assertFalse(form.is_valid()) |
246 | 246 | 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?")]}) |
248 | 248 | |
249 | 249 | def test_cleaned_data(self): |
250 | 250 | # Regression test |
… |
… |
class PasswordResetFormTest(TestCase):
|
295 | 295 | form = PasswordResetForm(data) |
296 | 296 | self.assertFalse(form.is_valid()) |
297 | 297 | 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.")]) |
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
|
13 | 13 | from django.core import mail |
14 | 14 | from django.core.urlresolvers import reverse |
15 | 15 | from django.http import QueryDict |
| 16 | from django.utils.translation import ugettext as _ |
16 | 17 | |
17 | 18 | |
18 | 19 | class AuthViewsTestCase(TestCase): |
… |
… |
class AuthViewsTestCase(TestCase):
|
47 | 48 | self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL)) |
48 | 49 | self.assertTrue(SESSION_KEY in self.client.session) |
49 | 50 | |
| 51 | def _(self, text): |
| 52 | escape = (('&', '&'), ('<', '<'), ('>', '>'), |
| 53 | ("'", '''), ('"', '"')) |
| 54 | return reduce(lambda x, y: x.replace(*y), escape, _(text).encode('utf-8')) |
50 | 55 | |
51 | 56 | class AuthViewNamedURLTests(AuthViewsTestCase): |
52 | 57 | urls = 'django.contrib.auth.urls' |
… |
… |
class PasswordResetTest(AuthViewsTestCase):
|
80 | 85 | response = self.client.get('/password_reset/') |
81 | 86 | self.assertEqual(response.status_code, 200) |
82 | 87 | response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'}) |
83 | | self.assertContains(response, "That e-mail address doesn'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?")) |
84 | 89 | self.assertEqual(len(mail.outbox), 0) |
85 | 90 | |
86 | 91 | def test_email_found(self): |
… |
… |
class PasswordResetTest(AuthViewsTestCase):
|
115 | 120 | response = self.client.get(path) |
116 | 121 | # redirect to a 'complete' page: |
117 | 122 | 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) |
119 | 124 | |
120 | 125 | def test_confirm_invalid(self): |
121 | 126 | url, path = self._test_confirm_start() |
… |
… |
class PasswordResetTest(AuthViewsTestCase):
|
125 | 130 | |
126 | 131 | response = self.client.get(path) |
127 | 132 | 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) |
129 | 134 | |
130 | 135 | def test_confirm_invalid_user(self): |
131 | 136 | # Ensure that we get a 200 response for a non-existant user, not a 404 |
132 | 137 | response = self.client.get('/reset/123456-1-1/') |
133 | 138 | 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) |
135 | 140 | |
136 | 141 | def test_confirm_overflow_user(self): |
137 | 142 | # Ensure that we get a 200 response for a base36 user id that overflows int |
138 | 143 | response = self.client.get('/reset/zzzzzzzzzzzzz-1-1/') |
139 | 144 | 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) |
141 | 146 | |
142 | 147 | def test_confirm_invalid_post(self): |
143 | 148 | # Same as test_confirm_invalid, but trying |
… |
… |
class PasswordResetTest(AuthViewsTestCase):
|
164 | 169 | # Check we can't use the link again |
165 | 170 | response = self.client.get(path) |
166 | 171 | 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) |
168 | 173 | |
169 | 174 | def test_confirm_different_passwords(self): |
170 | 175 | url, path = self._test_confirm_start() |
171 | 176 | response = self.client.post(path, {'new_password1': 'anewpassword', |
172 | 177 | 'new_password2':' x'}) |
173 | 178 | self.assertEqual(response.status_code, 200) |
174 | | self.assertTrue("The two password fields didn't match" in response.content) |
| 179 | self.assertTrue(self._(u"The two password fields didn't match.") in response.content) |
175 | 180 | |
176 | 181 | class ChangePasswordTest(AuthViewsTestCase): |
177 | 182 | |
… |
… |
class ChangePasswordTest(AuthViewsTestCase):
|
182 | 187 | } |
183 | 188 | ) |
184 | 189 | 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) |
186 | 191 | |
187 | 192 | def logout(self): |
188 | 193 | response = self.client.get('/logout/') |
… |
… |
class ChangePasswordTest(AuthViewsTestCase):
|
196 | 201 | } |
197 | 202 | ) |
198 | 203 | 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) |
200 | 205 | |
201 | 206 | def test_password_change_fails_with_mismatched_passwords(self): |
202 | 207 | self.login() |
… |
… |
class ChangePasswordTest(AuthViewsTestCase):
|
207 | 212 | } |
208 | 213 | ) |
209 | 214 | self.assertEqual(response.status_code, 200) |
210 | | self.assertTrue("The two password fields didn't match." in response.content) |
| 215 | self.assertTrue(self._(u"The two password fields didn't match.") in response.content) |
211 | 216 | |
212 | 217 | def test_password_change_succeeds(self): |
213 | 218 | self.login() |