我想测试
- 如果视图装饰器正常工作
- 如果调用了正确的视图
所以,这里的装饰器get_object
和视图features
在myapp.views
.
@get_object
def features(request, object):
return {}
我试着嘲笑这个:
new_view = Mock(__name__='features', return_value={})
decorated = get_object(new_view)
with patch('myapp.views.features') as features:
features = decorated
client = Client()
response = client.get('/features')
print new_view.call_args
这没有显示任何内容,好像没有调用模拟对象,尽管我想它应该是。
如何正确模拟装饰视图?