接口中导入Excel
Py文件
from requests_toolbelt.multipart.encoder import MultipartEncoder
@pytest.mark.parametrize('yaml_case', get_cases(data_yaml)) def test_custIndividualInfoImport(yaml_case): '''【客户信息】个人客户导入''' req_url = env_dict['host'] + data_yaml['interface'] filePath = yaml_case['body']['file'] m = MultipartEncoder( fields={ 'file': ('netOrderTest.xlsx', open(filePath, 'rb'), 'application/vnd.ms-excel'), 'entCertNo': yaml_case['body']['entCertNo'] }) # 拼接headers数据 headers['Content-Type'] = m.content_type results = requests.post(req_url, data=m, headers=headers, verify=False) print(json.dumps(results.json(), ensure_ascii=False)) Log().info('--test_case %s start--' % 'test_custIndividualInfoImport') Log().info('--request result %s' % results.json()) Log().info('--test_case %s end--' % 'test_custIndividualInfoImport') assert (results.json()['code'] == yaml_case['code'])
yaml文件
interface: /xxx/import test_cases: case-01-全部字段齐全: code: 200 body: file: 'C:\xxx\netOrderTest.xlsx' #导入excel entCertNo: '430423193904245431' #企业编号
本文来自博客园,作者:他还在坚持嘛,转载请注明原文链接:他还在坚持嘛 https://www.cnblogs.com/brf-test/p/16844247.html