Code

Ticket #16837: 16837.general_error_message.2.diff

File 16837.general_error_message.2.diff, 4.2 KB (added by Wim Feijen <wim@…>, 3 years ago)

Better error message: updated tests as well.

Line 
1diff --git a/django/contrib/admin/forms.py b/django/contrib/admin/forms.py
2index f26c100..e790e2e 100644
3--- a/django/contrib/admin/forms.py
4+++ b/django/contrib/admin/forms.py
5@@ -6,8 +6,8 @@ from django.contrib.auth.models import User
6 
7 from django.utils.translation import ugettext_lazy, ugettext as _
8 
9-ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. "
10-                              "Note that both fields are case-sensitive.")
11+ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password "
12+        "for a staff account. Note that both fields are case-sensitive.")
13 
14 class AdminAuthenticationForm(AuthenticationForm):
15     """
16diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
17index 22b65a6..291b050 100644
18--- a/tests/regressiontests/admin_views/tests.py
19+++ b/tests/regressiontests/admin_views/tests.py
20@@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse
21 from django.contrib.auth import REDIRECT_FIELD_NAME, admin
22 from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
23 from django.contrib.contenttypes.models import ContentType
24+from django.contrib.admin.forms import ERROR_MESSAGE
25 from django.contrib.admin.models import LogEntry, DELETION
26 from django.contrib.admin.sites import LOGIN_FORM_KEY
27 from django.contrib.admin.util import quote
28@@ -754,12 +755,12 @@ class AdminViewPermissionsTest(TestCase):
29         self.assertContains(login, "Your e-mail address is not your username")
30         # only correct passwords get a username hint
31         login = self.client.post('/test_admin/admin/', self.super_email_bad_login)
32-        self.assertContains(login, "Please enter a correct username and password.")
33+        self.assertContains(login, ERROR_MESSAGE)
34         new_user = User(username='jondoe', password='secret', email='super@example.com')
35         new_user.save()
36         # check to ensure if there are multiple e-mail addresses a user doesn't get a 500
37         login = self.client.post('/test_admin/admin/', self.super_email_login)
38-        self.assertContains(login, "Please enter a correct username and password.")
39+        self.assertContains(login, ERROR_MESSAGE)
40 
41         # Add User
42         request = self.client.get('/test_admin/admin/')
43@@ -790,7 +791,7 @@ class AdminViewPermissionsTest(TestCase):
44         self.assertEqual(request.status_code, 200)
45         login = self.client.post('/test_admin/admin/', self.joepublic_login)
46         self.assertEqual(login.status_code, 200)
47-        self.assertContains(login, "Please enter a correct username and password.")
48+        self.assertContains(login, ERROR_MESSAGE)
49 
50         # Requests without username should not return 500 errors.
51         request = self.client.get('/test_admin/admin/')
52@@ -1350,12 +1351,12 @@ class SecureViewTests(TestCase):
53         self.assertContains(login, "Your e-mail address is not your username")
54         # only correct passwords get a username hint
55         login = self.client.post('/test_admin/admin/secure-view/', self.super_email_bad_login)
56-        self.assertContains(login, "Please enter a correct username and password.")
57+        self.assertContains(login, ERROR_MESSAGE)
58         new_user = User(username='jondoe', password='secret', email='super@example.com')
59         new_user.save()
60         # check to ensure if there are multiple e-mail addresses a user doesn't get a 500
61         login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
62-        self.assertContains(login, "Please enter a correct username and password.")
63+        self.assertContains(login, ERROR_MESSAGE)
64 
65         # Add User
66         request = self.client.get('/test_admin/admin/secure-view/')
67@@ -1387,7 +1388,7 @@ class SecureViewTests(TestCase):
68         login = self.client.post('/test_admin/admin/secure-view/', self.joepublic_login)
69         self.assertEqual(login.status_code, 200)
70         # Login.context is a list of context dicts we just need to check the first one.
71-        self.assertContains(login, "Please enter a correct username and password.")
72+        self.assertContains(login, ERROR_MESSAGE)
73 
74         # 8509 - if a normal user is already logged in, it is possible
75         # to change user into the superuser without error