handle_req_data: sort data with keys if request data is json type

This commit is contained in:
httprunner
2017-06-24 11:19:20 +08:00
parent ebed17d741
commit 8339b7f2ab
5 changed files with 24 additions and 6 deletions

View File

@@ -17,6 +17,23 @@ def gen_md5(str_list):
authorization_str = "".join(str_list)
return hashlib.md5(authorization_str.encode('utf-8')).hexdigest()
def handle_req_data(data):
if not data:
return data
if isinstance(data, str):
# check if data in str can be converted to dict
try:
data = json.loads(data)
except ValueError:
pass
if isinstance(data, dict):
# sort data in dict with keys, then convert to str
data = json.dumps(data, sort_keys=True)
return data
def load_yaml_file(yaml_file):
with open(yaml_file, 'r+') as stream:
return yaml.load(stream)