• 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: []
  • 相关阅读:
    [TJOI2013]单词
    [AHOI2005]病毒检测
    [SCOI2016]围棋
    [SDOI2008]Sandy的卡片
    [POI2005]Sza-Template
    [Usaco2015 Feb]Censoring
    浅谈算法——KMP
    yii2邮件配置教程,报Expected response code 250 but got code "553"原因
    yii2设置发送邮件的一些配置
    js 的正则表达式 部分展示test()方法的验证功能
  • 原文地址:https://www.cnblogs.com/snailgirl/p/13071376.html
Copyright © 2020-2023  润新知