httpunner上传及下载文件

import os
from urllib.parse import quote,unquote


# 获取文件存放路径
dataFilesPath = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'dataFiles')

'''下载模板'''
def downloadExcel(response, param, fileType='xlsx'):
    content = response.content
    disposition = response.headers.get('Content-Disposition')
    if disposition:
        fileName = disposition.split('filename=')[1].replace('"', '').replace("'", "")
        # fileName = unquote(fileName,'utf-8') # 处理文件名称乱码
        # fileName = fileName.encode('ISO-8859-1').decode('utf-8') # 处理文件名称乱码
        fileName = param + '-' + fileName
    else:
        fileName = param + '.' + fileType
    with open(os.path.join(dataFilesPath, fileName), 'wb') as f:
        f.write(content)

'''读取文件内容'''
def get_file(fileName):
    filePath = os.path.join(dataFilesPath, fileName)
    return open(filePath, "rb")



# debugtalk
-   name: 模板下载
    api: api/模板下载/模板下载.yaml
    variables:
        name: 'table'
    validate: []
    teardown_hooks:
        - ${downloadExcel($response, 下载模板源)}
    output: []
-   name: 文档导入
    api: api/文档导入/文档导入.yaml
    variables:
        file: ['文档导入.xlsx', "${get_file(文档导入.xlsx)}"]
        type: [null, 'table']
    validate: []
    output: []
原文地址:https://www.cnblogs.com/snailgirl/p/13071376.html