开发者

django web app testing

I have the following in tests.py.

def setUp(self):
    self.client = Client()
    self.client.get('/homepage',{'join':'NPO2','siteid':1450})
    self.client.session.save()
    self.oraganisation_list = ['NPO1','NPO2','NPO3']
    self.pay_recursion_list = ['annual','monthly','bi-annual','quarter']
def test_paytermpage(self):
    for org in self.organisation_list:
        response = self.client.get('',{'join':org,'siteid':1450})
        self.failUnlessEqual(response.status_code,200)
        self.assertTemplateUsed(response,'some.html')
def test_infopage(self):
    for term in self.pay_recurstion_list:
        response = self.client.post('',{'pay-term':term,'submit':'payterm'})
        self.failUnlessEqual(response.status_code,200)

test_infopage() is failing and here is the traceback.

Traceback (most recent call last):
  File "/var/lib/django/bsdata/shoppingcart/tests.py", line 50, in test_infopage
    response = self.cl开发者_开发技巧ient.post('',{'pay-term':term,'submit':'payterm'})
  File "/usr/lib/pymodules/python2.6/django/test/client.py", line 313, in post
    response = self.request(**r)
  File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 92, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/var/lib/django/.../views.py", line 22, in start
    term,costdict,webobj = costInfo(request)
  File "/var/lib/django/...views.py", line 238, in getCostInfo
    cost_dict = Site.objects.getDict(request.session['siteid']) 
  File "/var/lib/django/.../managers.py", line 16, in getLoadedDict
    siteobj = Site.objects.get(pk=agent)
  File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 120, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 305, in get
    % self.model._meta.object_name)
DoesNotExist: Site matching query does not exist.

I did debug to see what value 'agent' in siteobj = Site.objects.get(pk=agent) is getting its a valid integer.

Surprisingly both of them are working when tested from shell like this

setup_test_environment()
client = Client()
client.get('/shoppingcart',{'join':'NPO1','siteid':1450})
client.session.save()
oraganisation_list = ['NPO1','NPO2','NPO3']
pay_recursion_list = ['annual','monthly','bi-annual','quarter']
for org in oraganisation_list:
    response = client.get('',{'join':org,'siteid':1450})
    TestCase.failUnlessEqual(t,response.status_code,200)
for term in pay_recursion_list:
    response = client.post('',{'pay-term':term,'submit':'payterm'})
    TestCase.failUnlessEqual(t,response.status_code,200)

Sorry for too much info,didn't know how to explain better. Any ideas would be highly helpful for this newbie. Thanks.


The Django test runner uses a different database than your production data. If your site requires a Site to exist, you should either add it in your Test setUp, or you should require a fixture that loads the site.


Try putting "SITE_ID = 1" in your settings. This is part of the sites framework.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜