fix 上传文件bug

This commit is contained in:
七月 2022-06-07 19:13:16 +08:00
parent e23a54ee89
commit aa1de35bc5
8 changed files with 264 additions and 11 deletions

View File

@ -1 +1 @@
22988
23301

View File

@ -1 +1 @@
loginUserName_wanandroid_com=18800000001;token_pass_wanandroid_com=5d9b90bcb70640183e09d1e755ead823;JSESSIONID=177BBBABDE1072E5AE24B63F87AB223C;loginUserName=18800000001;token_pass=5d9b90bcb70640183e09d1e755ead823;
loginUserName_wanandroid_com=18800000001;token_pass_wanandroid_com=5d9b90bcb70640183e09d1e755ead823;JSESSIONID=67C309F0E2F2AB74E27A803501F0AEB6;loginUserName=18800000001;token_pass=5d9b90bcb70640183e09d1e755ead823;

0
data/t1.py Normal file
View File

View File

@ -0,0 +1,2 @@
ERROR 2022-06-06 11:50:10,840 C:\work\Study\pytest-auto-api2\logs\error.log:conftest.py:133 异常用例数: 0
ERROR 2022-06-06 11:50:10,843 C:\work\Study\pytest-auto-api2\logs\error.log:conftest.py:134 失败用例数: 0

246
logs/info.log.2022-06-06 Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
WARNING 2022-06-06 11:50:10,844 C:\work\Study\pytest-auto-api2\logs\warning.log:conftest.py:135 跳过用例数: 1

View File

@ -101,13 +101,13 @@ class RequestControl:
return request_data, header
@classmethod
def file_prams_exit(cls, yaml_data, multipart):
def file_prams_exit(cls, yaml_data):
# 判断上传文件接口,文件参数是否存在
try:
params = yaml_data[YAMLDate.DATA.value]['params']
except KeyError:
params = None
return multipart, params
return params
@classmethod
def text_encode(cls, text):
@ -134,18 +134,18 @@ class RequestControl:
yaml_data = eval(cache_regular(str(yaml_data)))
_files = []
file_data = {}
# 兼容又要上传文件,又要上传其他类型参数
cls.file_data_exit(yaml_data, file_data)
for key, value in yaml_data[YAMLDate.DATA.value]['file'].items():
file_path = ConfigHandler.file_path + value
file_data[key] = (value, open(file_path, 'rb'), 'application/octet-stream')
_files.append(file_data)
# allure中展示该附件
allure_attach(source=file_path, name=value, extension=value)
# 兼容又要上传文件,又要上传其他类型参数
cls.file_data_exit(yaml_data, file_data)
multipart = cls.multipart_data(file_data)
yaml_data[YAMLDate.HEADER.value]['Content-Type'] = multipart.content_type
yaml_data, multipart = cls.file_prams_exit(yaml_data, multipart)
return yaml_data, multipart
params_data = cls.file_prams_exit(yaml_data)
return multipart, params_data, yaml_data
@log_decorator(True)
@execution_duration(3000)
@ -206,8 +206,9 @@ class RequestControl:
res = requests.request(method=_method, url=url, headers=_headers, verify=False, **kwargs)
# 判断上传文件
elif _requestType == RequestType.FILE.value:
yaml_data = eval(cache_regular(str(yaml_data)))
multipart = self.upload_file(yaml_data)
yaml_data = multipart[2]
_headers = multipart[2][YAMLDate.HEADER.value]
_headers = self.check_headers_str_null(_headers)
res = requests.request(method=_method, url=yaml_data[YAMLDate.URL.value],
data=multipart[0], params=multipart[1], headers=_headers, verify=False, **kwargs)

View File

@ -40,7 +40,7 @@ class TearDownHandler:
# jsonpath 数据解析
_new_data = jsonpath_replace(change_data=_change_data, key_name='_teardown_case')
# 最终提取到的数据,转换成 _teardown_case[xxx][xxx]
_new_data += ' = {0}'.format(replace_value)
_new_data += " = {0}".format(replace_value)
return _new_data
@classmethod
@ -129,11 +129,14 @@ class TearDownHandler:
_cache_data = Cache(i['cache_data']).get_cache()
# _cache_data = eval(cache_regular(str(i['cache_data'])))
_replace_key = i['replace_key']
# _teardown_case['data']['customerCode'] = 'CC20220607021'
# exec('_teardown_case[\'data\'][\'customerCode\'] = \'CC20220607047\'')
exec(self.jsonpath_replace_data(replace_key=_replace_key, replace_value=_cache_data))
self.teardown_sql(case_data)
print(_teardown_case)
test_case = self.regular_testcase(_teardown_case)
# res = self.teardown_http_requests(test_case)
res = self.teardown_http_requests(test_case)
Assert(test_case['assert']).assert_equality(response_data=res['response_data'],
sql_data=res['sql_data'], status_code=res['status_code'])