每天努力一点点,坚持下去 ------ 博客首页

接口中导入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' #企业编号

 

posted @ 2022-10-31 14:49  他还在坚持嘛  阅读(41)  评论(0编辑  收藏  举报