I03_HttpRunner上傳圖檔:file-tuple方式
接上篇,使用 'name': file-tuple 方式上傳檔案,根據傳入元組元素個數的不同,可以有三種形式:
- 2-tuple ``('filename', fileobj)
- 3-tuple ``('filename', fileobj, 'content_type')
- 4-tuple ``('filename', fileobj, 'content_type', custom_headers)
測試用例:
- config:
name: 百度識圖 - 上傳圖檔用例
variables:
# 調用 debugtalk.py 中的 get_file() 函數
p_filepath: ".\\dog.jpg"
p_fileobj: ${get_file($p_filepath)}
- test:
name: 上傳一張小狗的照片
request:
url: https://graph.baidu.com/upload
method: POST
# 上傳檔案:tuple 方式,傳入三個元素
files:
image: [dog.jpg, $p_fileobj, image/jpeg]
validate:
- eq: [status_code, 200]
- eq: [content.status, 0]
- eq: [content.msg, Success]
前面講,上傳檔案的參數格式可以為tuple方式,包括2-4個元素都可以,如:
files:
# 格式:2-tuple ``('filename', fileobj)
image: [dog,jpg, $p_fileobj]
files:
# 格式:3-tuple ``('filename', fileobj, 'content_type')
image: [dog.jpg, $p_fileobj, image/jpeg]