简体   繁体   中英

django test client trouble

I've got a problem... we're writing project using django, and i'm trying to use django.test.client with nose test-framework for tests.

Our code is like this:

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"]

and in nose output I catch:

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'

My settings.py file does have this attribute.

If I get the data from the server with standard urllib2.urllopen().read() it works in the proper way.

Any ideas how I can solve this case?

Shameless self-promotion: exactly for those reasons I made test library that enables you to test application with urllib2.

Docs are there: http://readthedocs.org/docs/django-sane-testing/en/latest/

Example of what You might want to do is, for example, in django-http-digest-tests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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