【问题标题】:Django Framework Test FailingDjango 框架测试失败
【发布时间】:2010-11-04 21:19:37
【问题描述】:

我正在使用 django-nonrel。当我在仅包含一个非常简单的用户定义测试的项目上运行manage.py test 时,我在输出中收到以下错误。有没有人见过这个?我需要做些什么来解决问题,以便test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests) 成功?

/src/google_appengine/google/appengine/datastore/datastore_stub_util.py:21: DeprecationWarning: the md5 module is deprecated; use hashlib instead
    import md5
/src/google_appengine/google/appengine/api/memcache/__init__.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
    import sha
/src/google_appengine/google/appengine/api/datastore_types.py:727: DeprecationWarning: object.__init__() takes no parameters
    super(Email, self).__init__(self, email)
............................................s.................F.....................................................................................................
======================================================================
FAIL: test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/src/django/contrib/contenttypes/tests.py", line 66, in test_shortcut_view
self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
AssertionError: 'http://example.com/users/john/' != '/users/john/'

----------------------------------------------------------------------
Ran 164 tests in 9.185s

FAILED (failures=1, skipped=1)

【问题讨论】:

    标签: python django django-nonrel unit-testing


    【解决方案1】:

    答案就在你的追溯中:

    self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
    AssertionError: 'http://example.com/users/john/' != '/users/john/'
    

    改变第一行:

    self.assertEqual("/users/john/", response._headers.get("location")[1])
    

    这应该修复测试。但如果它的测试代码不是你写的,我认为问题出在 example.com/ 部分。 example.com 可能来自您的站点设置。如果您将其更改为正确的 url,则有一个名为 sites 的模型,这可能会起作用。

    还有

    您可以尝试使用不同的 django 版本。主干版本和稳定版本在测试期间的行为不同。

    【讨论】:

    • 看起来它是我当时拥有的 django-nonrel 版本中的一个问题,而不是我需要通过配置或类似的东西解决的问题。谢谢!
    【解决方案2】:

    失败是由默认 django 设置附带的单元测试引起的。

    他们希望您使用管理界面配置默认站点:

    例如http://localhost:8000/admin/sites/ 并拥有 SITE_ID = 1

    检查站点 ID 是否引用了有效条目

    http://localhost:8000/admin/sites/site/1/ 其中 1 是您的站点 ID。

    --

    使用站点应用程序是可选的,您可以删除: 'django.contrib.sites', 从您的应用列表中。

    【讨论】:

      猜你喜欢
      • 2014-08-31
      • 2018-03-14
      • 2014-05-26
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多