Opened 11 years ago
Closed 11 years ago
#20796 closed Bug (duplicate)
AUTHENTICATION_BACKENDS RemoteUserBackend breaks tests
Reported by: | python_monster | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | timograham@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
After creating a new django (1, 5, 1, 'final', 0) project, configuring RemoteUser functionality breaks tests:
settings.py
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3' DATABASES['default']['NAME'] = 'proj.db' MIDDLEWARE_CLASSES += ( 'django.contrib.auth.middleware.RemoteUserMiddleware',) AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.RemoteUserBackend', 'django.contrib.auth.backends.ModelBackend', )
python manage.py test auth.RemoteUserCustomTest
Creating test database for alias 'default'... FFF.F ====================================================================== FAIL: test_header_disappears (django.contrib.auth.tests.remote_user.RemoteUserCustomTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/virtualenv/proj/lib/python2.7/site-packages/django/contrib/auth/tests/remote_user.py", line 109, in test_header_disappears self.assertEqual(response.context['user'].username, 'knownuser') AssertionError: 'knownuser@example.com' != 'knownuser' ====================================================================== FAIL: test_known_user (django.contrib.auth.tests.remote_user.RemoteUserCustomTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/virtualenv/proj/lib/python2.7/site-packages/django/contrib/auth/tests/remote_user.py", line 188, in test_known_user super(RemoteUserCustomTest, self).test_known_user() File "/opt/virtualenv/proj/lib/python2.7/site-packages/django/contrib/auth/tests/remote_user.py", line 71, in test_known_user self.assertEqual(response.context['user'].username, 'knownuser') AssertionError: 'knownuser@example.com' != 'knownuser' ====================================================================== FAIL: test_last_login (django.contrib.auth.tests.remote_user.RemoteUserCustomTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/virtualenv/proj/lib/python2.7/site-packages/django/contrib/auth/tests/remote_user.py", line 99, in test_last_login self.assertEqual(default_login, response.context['user'].last_login) AssertionError: datetime.datetime(2000, 1, 1, 0, 0, tzinfo=<UTC>) != datetime.datetime(2013, 7, 24, 8, 2, 15, 485797, tzinfo=<UTC>) ====================================================================== FAIL: test_unknown_user (django.contrib.auth.tests.remote_user.RemoteUserCustomTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/virtualenv/proj/lib/python2.7/site-packages/django/contrib/auth/tests/remote_user.py", line 198, in test_unknown_user self.assertEqual(newuser.email, 'user@example.com') AssertionError: u'' != 'user@example.com' ---------------------------------------------------------------------- Ran 5 tests in 0.071s FAILED (failures=4) Destroying test database for alias 'default'...
python manage.py test auth.RemoteUserNoCreateTest
Creating test database for alias 'default'... ....F ====================================================================== FAIL: test_unknown_user (django.contrib.auth.tests.remote_user.RemoteUserNoCreateTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/virtualenv/proj/lib/python2.7/site-packages/django/contrib/auth/tests/remote_user.py", line 145, in test_unknown_user self.assertTrue(response.context['user'].is_anonymous()) AssertionError: False is not true ---------------------------------------------------------------------- Ran 5 tests in 0.440s FAILED (failures=1) Destroying test database for alias 'default'...
Note:
See TracTickets
for help on using tickets.
By listing
'django.contrib.auth.backends.RemoteUserBackend'
in your settings, it's causing the failing tests to use that backend rather than'django.contrib.auth.tests.test_remote_user.CustomRemoteUserBackend'
. We could fix this by prepending (rather than appending)self.backend
in thesetUp
method - that would fix the first set of failures.However, the failing test in
RemoteUserCustomTest
actually requires'django.contrib.auth.backends.RemoteUserBackend'
not to be inAUTHENTICATION_BACKENDS
since the user does authenticate against that backend. I suppose the tests need to be rewritten not to depend on the values ofsettings.AUTHENTICATION_BACKENDS
?