support https protocol
This commit is contained in:
parent
c3f86ca475
commit
c8e4a7a8c0
|
@ -37,6 +37,10 @@ def write_case(case_path, auto_yaml=True):
|
|||
if not os.path.exists(case_path):
|
||||
os.makedirs(case_path)
|
||||
|
||||
# 判断测试用例脚本是否存在
|
||||
if os.path.exists(test_script):
|
||||
continue
|
||||
|
||||
# 替换模板内容
|
||||
file_data = ''
|
||||
with open(temp_file, "r", encoding="utf-8") as f:
|
||||
|
|
|
@ -49,6 +49,9 @@ def write_case_yaml(har_path):
|
|||
|
||||
# 定义api通过配置
|
||||
api_config = dict()
|
||||
api_config['cookies'] = None
|
||||
api_config['scheme'] = har_ct["scheme"]
|
||||
api_config['host'] = host + ':' + str(port)
|
||||
simp_header = dict()
|
||||
for header in headers:
|
||||
# 去除基础请求头
|
||||
|
@ -63,13 +66,11 @@ def write_case_yaml(har_path):
|
|||
'Accept-Language']
|
||||
if header['name'] not in base_header:
|
||||
simp_header[header['name']] = header['value']
|
||||
api_config['host'] = host+':'+str(port)
|
||||
# 判断是否存在自定义消息头
|
||||
if simp_header:
|
||||
api_config['headers'] = simp_header
|
||||
else:
|
||||
api_config['headers'] = None
|
||||
api_config['cookies'] = None
|
||||
# 检查是否已存在项目配置信息,没有则写入
|
||||
rconfig = read_yaml_data(API_CONFIG)
|
||||
if rconfig:
|
||||
|
@ -85,7 +86,7 @@ def write_case_yaml(har_path):
|
|||
test_info = dict()
|
||||
test_info["title"] = module
|
||||
test_info["host"] = '${host}'
|
||||
test_info["scheme"] = har_ct["scheme"]
|
||||
test_info["scheme"] = '${scheme}' # har_ct["scheme"]
|
||||
test_info["method"] = method
|
||||
test_info["address"] = path
|
||||
test_info["mime_type"] = har_ct["request"]["mimeType"]
|
||||
|
@ -107,12 +108,16 @@ def write_case_yaml(har_path):
|
|||
else:
|
||||
parameter_list = har_ct["query"]
|
||||
|
||||
if "&" in parameter_list:
|
||||
for key in parameter_list.split("&"):
|
||||
val = key.split("=")
|
||||
parameter[val[0]] = val[1]
|
||||
if parameter_list:
|
||||
if "&" in parameter_list:
|
||||
for key in parameter_list.split("&"):
|
||||
val = key.split("=")
|
||||
parameter[val[0]] = val[1]
|
||||
else:
|
||||
parameter = json.loads(parameter_list)
|
||||
else:
|
||||
parameter = json.loads(parameter_list)
|
||||
parameter = None
|
||||
|
||||
except Exception as e:
|
||||
logging.error("未找到parameter: %s" % e)
|
||||
raise e
|
||||
|
|
|
@ -42,21 +42,24 @@ def post(headers, address, mime_type, timeout=10, data=None, files=None, cookies
|
|||
data=enc,
|
||||
headers=headers,
|
||||
timeout=timeout,
|
||||
cookies=cookies)
|
||||
elif 'data' in mime_type:
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
elif 'application/json' in mime_type:
|
||||
response = requests.post(url=address,
|
||||
data=data,
|
||||
headers=headers,
|
||||
timeout=timeout,
|
||||
files=files,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
else:
|
||||
response = requests.post(url=address,
|
||||
json=data,
|
||||
headers=headers,
|
||||
timeout=timeout,
|
||||
files=files,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
try:
|
||||
if response.status_code != 200:
|
||||
return response.status_code, response.text
|
||||
|
@ -86,9 +89,10 @@ def get(headers, address, data, timeout=8, cookies=None):
|
|||
params=data,
|
||||
headers=headers,
|
||||
timeout=timeout,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
if response.status_code == 301:
|
||||
response = requests.get(url=response.headers["location"])
|
||||
response = requests.get(url=response.headers["location"], verify=False)
|
||||
try:
|
||||
return response.status_code, response.json()
|
||||
except json.decoder.JSONDecodeError:
|
||||
|
@ -122,7 +126,8 @@ def put(headers, address, mime_type, timeout=8, data=None, files=None, cookies=N
|
|||
headers=headers,
|
||||
timeout=timeout,
|
||||
files=files,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
try:
|
||||
return response.status_code, response.json()
|
||||
except json.decoder.JSONDecodeError:
|
||||
|
@ -149,7 +154,8 @@ def delete(headers, address, data, timeout=8, cookies=None):
|
|||
params=data,
|
||||
headers=headers,
|
||||
timeout=timeout,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
try:
|
||||
return response.status_code, response.json()
|
||||
except json.decoder.JSONDecodeError:
|
||||
|
@ -180,14 +186,16 @@ def save_cookie(headers, address, mime_type, timeout=8, data=None, files=None, c
|
|||
headers=headers,
|
||||
timeout=timeout,
|
||||
files=files,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
else:
|
||||
response = requests.post(url=address,
|
||||
json=data,
|
||||
headers=headers,
|
||||
timeout=timeout,
|
||||
files=files,
|
||||
cookies=cookies)
|
||||
cookies=cookies,
|
||||
verify=False)
|
||||
try:
|
||||
cookies = response.cookies.get_dict()
|
||||
# 读取api配置并写入最新的cookie结果
|
||||
|
|
Loading…
Reference in New Issue