django:来自 django.contrib.auth 的测试失败

标签 django testing django-authentication django-contrib

当我运行我的 django 测试时,我得到以下错误,这些错误不在我的测试套件中:

======================================================================
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

谁能解释一下,我做错了什么或者我应该设置什么才能通过这些测试?

最佳答案

我通过执行以下操作成功地重现了您看到的测试结果:

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

如果您有这些行,请尝试删除它们并重新运行单元测试。但是,我对此没有解决方案。

关于django:来自 django.contrib.auth 的测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2507210/

相关文章:

python - django.contrib.auth 中的哪个函数创建默认模型权限?

Django:保存模型时填充用户 ID

python - 保存有循环外键的Django模型时,如何一次全部保存?

python - 即使用户已经登录,也会显示登录页面

java - greenmail 服务器收不到邮件

c# - 如何在 Rhino Mocks 3.6 中将 Expect 设置为扩展方法

java - 测试两个集合是否具有相同内容的最简单方法?

python - Django - 根据用户组过滤下拉选项

mysql - django:iregex 区分大小写

django - 是否可以在不修改 Form 类的情况下使用 django-crispy-form FormHelper