python - Fast api TestClient 发布文件列表
问题描述
我正在尝试测试获取文件列表的 fastapi 路由器。在使用 JS 的 html 请求中它的工作,但我需要测试它。我正在使用来自 fastapi 的 TestClient,当我尝试发送列表时,我得到状态代码 422,所以我去哪个文档并尝试 dict
,但我只得到 1 个文件的列表。
路由器
@router.post('/uploadone')
async def upload_file(response: Response,files:List = File(...)):
try:
properties = json.loads(files[len(files)-1])
check_file_type(files[:len(files)-1])
测试
def test_uploadone(self):
with open('upload_data/system_test/properties.json', 'rb') as file1:
json_file = json.load(file1)
with open('upload_data/system_test/heatmap1.csv', 'rb') as file:
body = file.read()
response = self.client.post('/actions/uploadone',
files={'files':('design_matrix1.csv', body),'json':
('prop.json', json.dumps(json_file))})
self.assertTrue(response.status_code == 200)
谢谢你的帮助
解决方案
推荐阅读
- vue.js - Vue - 将参数作为道具传递给路由是未定义的
- angular - 组件的初始值未定义
- node.js - 404 - 从 nginx 应用程序到远程服务器 localhost?
- laravel - 不返回任何通知
- gradle - Gradle左移运算符(<<)与doLast行为差异
- python - 如何从密集层的所有预测输出中以最大概率获得输出?
- java - 转换日期中的“使用excel方法”数值 - java
- docker - 我在哪里可以找到 docker 的 nginx(稳定)?
- java - 如何测量 Spring Web 应用程序中的组件启动时间?
- spring - Spring项目依赖项不需要的默认行为而不被使用