我有以下测试
def test_bulk_post(my_faker,factory):
snippets = [{'code':'print(True)'},{'code':'print(True)'},{'code':'print(True)'}]
assert factory.post('/snippets/',snippets) == True
我正在尝试扩展本教程中的代码片段应用程序,以在单个发布请求中接受多个代码对象。
现在,这给了我:
/venv/lib/python3.8/site-packages/django/test/client.py(244)encode_multipart()
*** AttributeError: 'list' object has no attribute 'items'
所以它不希望有一个列表。但是我想给它一个。我怎么做?
默认情况下,factory.post需要键,值对,但multipart/form-data
不列出因此出错
您可能应该设置content_type='application/json'
为将数据作为JSON主体传递
factory.post('/snippets/',snippets, content_type='application/json )
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句