【发布时间】:2012-04-26 05:52:55
【问题描述】:
我有一个从单元测试调用的函数。通过设置一些调试跟踪,我知道该函数像一个魅力一样工作,并且所有值都正确准备好返回。
这就是我的测试代码的样子(看看我的 ipdb.set_trace() 在哪里):
@override_settings(REGISTRATION_OPEN=True)
def test_confirm_account(self):
""" view that let's a user confirm account creation and username
when loggin in with social_auth """
request = self.factory.get('')
request.user = AnonymousUser()
request.session={}
request.session.update({self.pipename:{'backend':'facebook',
'kwargs':{'username':'Chuck Norris','response':{'id':1}}}})
# this is the function of which i need the context:
response = confirm_account(request)
self.assertEqual(response.context['keytotest'],'valuetotest')
据我从this part of the Django docs 了解到的,当我使用测试客户端时,我将能够访问 response.context。但是当我尝试像我那样访问 response.context 时,我得到了这个:
AttributeError: 'HttpResponse' 对象没有属性 'context'
有没有办法在不使用客户端的情况下获取客户端的特殊HttpResponse对象?
【问题讨论】:
标签: django django-views django-testing