我正在尝试测试获取文件列表的 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)
谢谢你的帮助