django:从django.contrib.auth失败的测试 [英] django: failing tests from django.contrib.auth

查看:141
本文介绍了django:从django.contrib.auth失败的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的django测试我得到以下错误,这是在我的测试套件之外:

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?

推荐答案

我已经设法通过执行以下操作重现您所看到的测试结果:

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.

这篇关于django:从django.contrib.auth失败的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆