Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#9183 closed (duplicate)

Using LocaleMiddleware breaks django.contrib.auth unittests

Reported by: Bruno Bord Owned by: nobody
Component: Testing framework Version: 1.0
Severity: Keywords:
Cc: karld@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When you activate django.middleware.locale.LocaleMiddleware in your middleware classes, the auth unittests are broken. Here's how...

  • Create a simple django project, no app, no module.
  • Change the database settings, please note that in order to pass the tests, you need to add 'django.contrib.admin' to the INSTALLED_APPS list.
  • change the urls.py to activate the admin site.
  • run a syncdb routine
  • run the tests by typing python manage.py test

And they pass.

Now here's an extract from my settings

LANGUAGE_CODE = 'fr'

# ...

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

And if I run the tests here's the output:

$ ./manage.py test
Creating test database...
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
FFFFFF.F.F......
======================================================================
FAIL: test_password_change_fails_with_invalid_old_password (django.contrib.auth.tests.views.ChangePasswordTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 139, in test_password_change_fails_with_invalid_old_password
    self.assert_("Your old password was entered incorrectly. Please enter it again." in response.content)
AssertionError

======================================================================
FAIL: test_password_change_fails_with_mismatched_passwords (django.contrib.auth.tests.views.ChangePasswordTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 150, in test_password_change_fails_with_mismatched_passwords
    self.assert_("The two password fields didn't match." in response.content)
AssertionError

======================================================================
FAIL: test_password_change_succeeds (django.contrib.auth.tests.views.ChangePasswordTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 162, in test_password_change_succeeds
    self.fail_login()
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 125, in fail_login
    self.assert_("Please enter a correct username and password. Note that both fields are case-sensitive." in response.content)
AssertionError

======================================================================
FAIL: test_confirm_complete (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 83, in test_confirm_complete
    self.assert_("The password reset link was invalid" in response.content)
AssertionError

======================================================================
FAIL: test_confirm_different_passwords (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 90, in test_confirm_different_passwords
    self.assert_("The two password fields didn't match" in response.content)
AssertionError

======================================================================
FAIL: test_confirm_invalid (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 56, in test_confirm_invalid
    self.assert_("The password reset link was invalid" in response.content)
AssertionError

======================================================================
FAIL: test_confirm_valid (django.contrib.auth.tests.views.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 46, in test_confirm_valid
    self.assert_("Please enter your new password" in response.content)
AssertionError

======================================================================
FAIL: Error is raised if the provided email address isn't currently registered
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bruno/bin/latest_django/django/contrib/auth/tests/views.py", line 19, in test_email_not_found
    self.assertContains(response, "That e-mail address doesn't have an associated user account")
  File "/home/bruno/bin/latest_django/django/test/testcases.py", line 274, in assertContains
    "Couldn't find '%s' in response" % text)
AssertionError: Couldn't find 'That e-mail address doesn't have an associated user account' in response

----------------------------------------------------------------------
Ran 16 tests in 1.155s

FAILED (failures=8)
Destroying test database...

They're all the same sort of failures. The test expects a string to be displayed in the response, but this string is in english, and the Locale Middleware sends it translated into French.

Change History (3)

comment:1 by anonymous, 16 years ago

Cc: karld@… added

comment:2 by Koen Biermans <koen.biermans@…>, 16 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of #8752, to which I just attached a patch.

comment:3 by lifengmds@…, 15 years ago

I met this problem too

Note: See TracTickets for help on using tickets.
Back to Top