天天看点

I03_HttpRunner上传图片:file-tuple方式

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]  
           

继续阅读