WebFileUpload.py
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/8/12 下午5:35
# @Author : 付孟奇
import unittest, requests
from config.vendorHost import vendor_host
from config.vendorPath import global_path, file_pdf_path
from util.generate import getTestCase
from util.log import logger
from util.HandleJson import file_read_global, file_readAPI
import warnings
class WebFileUpload(unittest.TestCase):
def testFunc(self):
'''Web端上传文件'''
warnings.simplefilter('ignore', ResourceWarning)
data_list = getTestCase('WEB_api_case.xlsx', 'Web端上传文件')
for i in range(len(data_list)):
self.getTest(data_list[i])
def getTest(self, data):
tcname = data['tc_name']
code = int(data['code'])
productCode = data['productCode']
api_type = 're'
logger.info('********************【' + tcname + '】接口测试开始!' + '********************')
headers = {
'X-Auth-Token': file_read_global('web_login', 'token')
}
payload = {
# 'docName': 'apitest.pdf',
'docType': file_read_global('fileList', 'docType'),
'productCode': productCode,
'checkedChannelArr': file_read_global('channel', 'channel_name'),
'checkedCityArr': file_read_global('organization', 'subBranchId'),
'checkedProvinceArr': file_read_global('organization', 'branchId'),
}
files = [
('file', ('apitest.pdf',
open(file_pdf_path, 'rb'), "application/pdf"))
]
url = vendor_host + api_type + file_readAPI(api_type, 'uploadFileUsingPOST')
response = requests.post(url, headers=headers, data=payload, files=files)
logger.info(response.text)