繁体   English   中英

django测试客户端故障

[英]django test client trouble

我有一个问题...我们正在使用django编写项目,而我正在尝试将django.test.client与鼻子测试框架一起用于测试。

我们的代码是这样的:

from simplejson import loads
from urlparse import urljoin

from django.test.client import Client

TEST_URL = "http://smakly.localhost:9090/"

def test_register():

    cln = Client()

    ref_data = {"email": "unique@mail.com", "name": "Василий", "website": "http://hot.bear.com", "xhr": "true"}

    print urljoin(TEST_URL, "/accounts/register/")
    response = loads(cln.post(urljoin(TEST_URL, "/accounts/register/"), ref_data))

    print response["message"]

在鼻子输出中,我发现:

Traceback (most recent call last):
  File "/home/psih/work/svn/smakly/eggs/nose-0.11.1-py2.6.egg/nose/case.py", line 183, in runTest
    self.test(*self.arg)
  File "/home/psih/work/svn/smakly/src/smakly.tests/smakly/tests/frontend/test_profile.py", line 25, in test_register
    response = loads(cln.post(urljoin(TEST_URL, "/accounts/register/"), ref_data))
  File "/home/psih/work/svn/smakly/parts/django/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/home/psih/work/svn/smakly/parts/django/django/test/client.py", line 225, in request
    response = self.handler(environ)
  File "/home/psih/work/svn/smakly/parts/django/django/test/client.py", line 69, in __call__
    response = self.get_response(request)
  File "/home/psih/work/svn/smakly/parts/django/django/core/handlers/base.py", line 78, in get_response
    urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
  File "/home/psih/work/svn/smakly/parts/django/django/utils/functional.py", line 273, in __getattr__
    return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'

我的settings.py文件确实具有此属性。

如果我使用标准的urllib2.urllopen().read()从服务器获取数据,则它将以正确的方式工作。

有什么想法可以解决这个问题吗?

无耻的自我推广:正是出于这些原因,我制作了测试库,使您能够使用urllib2测试应用程序。

文件在那里: http : //readthedocs.org/docs/django-sane-testing/en/latest/

例如, 在django-http-digest-tests中 ,您可能想做的事示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM