#9183: Using LocaleMiddleware breaks django.contrib.auth unittests
-------------------------------+--------------------------------------------
 Reporter:  Bruno Bord         |       Owner:  nobody    
   Status:  new                |   Milestone:            
Component:  Testing framework  |     Version:  1.0       
 Keywords:                     |       Stage:  Unreviewed
Has_patch:  0                  |  
-------------------------------+--------------------------------------------
 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.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9183>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to