我有一个自定义函数来验证请求。我试着在测试过程中模仿这个模块,但到目前为止还没有运气
这是我的观点
from auth_utils import authenticate_request, UnauthenticatedRequest
def my_view(request):
try:
authenticate_request(request)
except UnauthenticatedRequest:
return Http404()
return render(request, 'ok.html', {'status': 'ok'})
在测试中,我试图模拟authenticate_request
,这样它就不会产生错误
不能让它工作。有什么建议吗?在
谢谢,Python2.7,Django1.8。在
您需要模拟函数
authenticate_request
,它是在哪里导入的,而不是定义在哪里。在因此,例如,如果
my_view
是在myapp/views.py
中定义的,那么authenticate_request
将被导入myapp.views
。所以你可以这样称呼:相关问题 更多 >
编程相关推荐