Ticket #16837: 16837.general_error_message.2.diff

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

Better error message: updated tests as well.

  • django/contrib/admin/forms.py

    diff --git a/django/contrib/admin/forms.py b/django/contrib/admin/forms.py
    index f26c100..e790e2e 100644
    a b from django.contrib.auth.models import User 
    66
    77from django.utils.translation import ugettext_lazy, ugettext as _
    88
    9 ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. "
    10                               "Note that both fields are case-sensitive.")
     9ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password "
     10        "for a staff account. Note that both fields are case-sensitive.")
    1111
    1212class AdminAuthenticationForm(AuthenticationForm):
    1313    """
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 22b65a6..291b050 100644
    a b from django.core.urlresolvers import reverse 
    1414from django.contrib.auth import REDIRECT_FIELD_NAME, admin
    1515from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
    1616from django.contrib.contenttypes.models import ContentType
     17from django.contrib.admin.forms import ERROR_MESSAGE
    1718from django.contrib.admin.models import LogEntry, DELETION
    1819from django.contrib.admin.sites import LOGIN_FORM_KEY
    1920from django.contrib.admin.util import quote
    class AdminViewPermissionsTest(TestCase): 
    754755        self.assertContains(login, "Your e-mail address is not your username")
    755756        # only correct passwords get a username hint
    756757        login = self.client.post('/test_admin/admin/', self.super_email_bad_login)
    757         self.assertContains(login, "Please enter a correct username and password.")
     758        self.assertContains(login, ERROR_MESSAGE)
    758759        new_user = User(username='jondoe', password='secret', email='super@example.com')
    759760        new_user.save()
    760761        # check to ensure if there are multiple e-mail addresses a user doesn't get a 500
    761762        login = self.client.post('/test_admin/admin/', self.super_email_login)
    762         self.assertContains(login, "Please enter a correct username and password.")
     763        self.assertContains(login, ERROR_MESSAGE)
    763764
    764765        # Add User
    765766        request = self.client.get('/test_admin/admin/')
    class AdminViewPermissionsTest(TestCase): 
    790791        self.assertEqual(request.status_code, 200)
    791792        login = self.client.post('/test_admin/admin/', self.joepublic_login)
    792793        self.assertEqual(login.status_code, 200)
    793         self.assertContains(login, "Please enter a correct username and password.")
     794        self.assertContains(login, ERROR_MESSAGE)
    794795
    795796        # Requests without username should not return 500 errors.
    796797        request = self.client.get('/test_admin/admin/')
    class SecureViewTests(TestCase): 
    13501351        self.assertContains(login, "Your e-mail address is not your username")
    13511352        # only correct passwords get a username hint
    13521353        login = self.client.post('/test_admin/admin/secure-view/', self.super_email_bad_login)
    1353         self.assertContains(login, "Please enter a correct username and password.")
     1354        self.assertContains(login, ERROR_MESSAGE)
    13541355        new_user = User(username='jondoe', password='secret', email='super@example.com')
    13551356        new_user.save()
    13561357        # check to ensure if there are multiple e-mail addresses a user doesn't get a 500
    13571358        login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
    1358         self.assertContains(login, "Please enter a correct username and password.")
     1359        self.assertContains(login, ERROR_MESSAGE)
    13591360
    13601361        # Add User
    13611362        request = self.client.get('/test_admin/admin/secure-view/')
    class SecureViewTests(TestCase): 
    13871388        login = self.client.post('/test_admin/admin/secure-view/', self.joepublic_login)
    13881389        self.assertEqual(login.status_code, 200)
    13891390        # Login.context is a list of context dicts we just need to check the first one.
    1390         self.assertContains(login, "Please enter a correct username and password.")
     1391        self.assertContains(login, ERROR_MESSAGE)
    13911392
    13921393        # 8509 - if a normal user is already logged in, it is possible
    13931394        # to change user into the superuser without error
Back to Top