5

When I run my django test I get following errors, that are outside of my test suite:

======================================================================
ERROR: test_known_user (django.contrib.auth.tests.remote_user.RemoteUserCustomTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 160, in test_known_user
    super(RemoteUserCustomTest, self).test_known_user()
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 67, in test_known_user
    self.assertEqual(response.context['user'].username, 'knownuser')
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_last_login (django.contrib.auth.tests.remote_user.RemoteUserCustomTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 87, in test_last_login
    self.assertNotEqual(default_login, response.context['user'].last_login)
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_no_remote_user (django.contrib.auth.tests.remote_user.RemoteUserCustomTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 33, in test_no_remote_user
    self.assert_(isinstance(response.context['user'], AnonymousUser))
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_unknown_user (django.contrib.auth.tests.remote_user.RemoteUserCustomTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 168, in test_unknown_user
    super(RemoteUserCustomTest, self).test_unknown_user()
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 51, in test_unknown_user
    self.assertEqual(response.context['user'].username, 'newuser')
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_known_user (django.contrib.auth.tests.remote_user.RemoteUserNoCreateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 67, in test_known_user
    self.assertEqual(response.context['user'].username, 'knownuser')
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_last_login (django.contrib.auth.tests.remote_user.RemoteUserNoCreateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 87, in test_last_login
    self.assertNotEqual(default_login, response.context['user'].last_login)
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_no_remote_user (django.contrib.auth.tests.remote_user.RemoteUserNoCreateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 33, in test_no_remote_user
    self.assert_(isinstance(response.context['user'], AnonymousUser))
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_unknown_user (django.contrib.auth.tests.remote_user.RemoteUserNoCreateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 118, in test_unknown_user
    self.assert_(isinstance(response.context['user'], AnonymousUser))
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_known_user (django.contrib.auth.tests.remote_user.RemoteUserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 67, in test_known_user
    self.assertEqual(response.context['user'].username, 'knownuser')
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_last_login (django.contrib.auth.tests.remote_user.RemoteUserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 87, in test_last_login
    self.assertNotEqual(default_login, response.context['user'].last_login)
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_no_remote_user (django.contrib.auth.tests.remote_user.RemoteUserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 33, in test_no_remote_user
    self.assert_(isinstance(response.context['user'], AnonymousUser))
TypeError: 'NoneType' object is unsubscriptable

======================================================================
ERROR: test_unknown_user (django.contrib.auth.tests.remote_user.RemoteUserTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/remote_user.py", line 51, in test_unknown_user
    self.assertEqual(response.context['user'].username, 'newuser')
TypeError: 'NoneType' object is unsubscriptable

======================================================================
FAIL: test_current_site_in_context_after_login (django.contrib.auth.tests.views.LoginTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/django/contrib/auth/tests/views.py", line 190, in test_current_site_in_context_after_login
    self.assertEquals(response.status_code, 200)
AssertionError: 302 != 200

Could anyone explain me, what am I doing wrong or what I should set to get those tests pass?

gruszczy
  • 40,948
  • 31
  • 128
  • 181
  • It would help if you posted your code which is producing the errors. – MHarrison Mar 24 '10 at 11:46
  • I really have no idea what snippet I could post. This is a already a little big project and all my tests (about 90) work fine. I just have problems with those from contrib.auth. – gruszczy Mar 24 '10 at 12:22

3 Answers3

2

I have managed to reproduce the test results you are seeing by doing the following:

MIDDLEWARE_CLASSES = (
    'django.middleware.cache.UpdateCacheMiddleware',
    .... <your middleware classes> ....
    'django.middleware.cache.FetchFromCacheMiddleware',
)

If you have these lines, try removing them and re-running the unit test. I do not however have a solution for this.

Derek Kwok
  • 12,768
  • 6
  • 38
  • 58
  • I'm pretty sure this is a bug. I filed [ticket #14105](http://code.djangoproject.com/ticket/14105) – Pete Aug 12 '10 at 23:04
0

Looks like you haven't got the 'user' key available in your context, or even no context at all...

In your settings.py do you have the following?

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.media",
    "django.core.context_processors.request",

     etc ....
)

Indeed, do you have TEMPLATE_CONTEXT_PROCESSORS at all? IIRC django-admin.py startproject doesn't actually include these in the default settings.py

Hope that helps

Steve

Steve Jalim
  • 11,989
  • 1
  • 37
  • 54
  • I don't have TEMPLATE_CONTEXT_PROCESSOR in my settings, but when I added above line codes it didn't help. – gruszczy Mar 24 '10 at 11:58
  • TEMPLATE_CONTEXT_PROCESSOR or TEMPLATE_CONTEXT_PROCESSORS (note the 'S') – Steve Jalim Mar 24 '10 at 13:03
  • Also, which version of Django are you on? http://osdir.com/ml/DjangoUsers/2009-05/msg00282.html implies a fix was pushed to trunk last year --> http://code.djangoproject.com/changeset/10674 – Steve Jalim Mar 24 '10 at 13:06
0

If you have Python 2.6.5, you need this patch: http://code.djangoproject.com/changeset/11821 .

Otherwise, did you import django.contrib.admin? There are certain templates that need to exist for django.contrib.auth 's tests (your code shouldn't be affected if they are not there) to work, and django.contrib.admin happens to provide them.

Macha
  • 14,366
  • 14
  • 57
  • 69
  • Where should I make the import? In tests? I do have Python 2.6.5, but I really wouldn't like to patch my django this way and would rather wait for official release I could install. – gruszczy Apr 07 '10 at 12:46
  • You should import it in your settings.py (add it to the list of INSTALLED_APPS ). However, with Python 2.6.5, it will fail without the patch regardless. If you don't want to apply it, I guess you'll have to wait until the release of 1.1.2. – Macha Apr 07 '10 at 13:21
  • I have installed 1.1.2, but this didn't help. So I guess it's not the problem. – gruszczy May 19 '10 at 10:55