mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-16 23:47:37 +08:00
update lower_dict_keys, avoid mistakes in OrderDict
This commit is contained in:
31
ate/utils.py
31
ate/utils.py
@@ -287,31 +287,28 @@ def search_conf_item(start_path, item_type, item_name):
|
||||
|
||||
return search_conf_item(dir_path, item_type, item_name)
|
||||
|
||||
def lower_dict_key(origin_dict, depth=1):
|
||||
""" convert dict key to lower case, with depth control supported.
|
||||
def lower_dict_keys(origin_dict):
|
||||
""" convert keys in dict to lower case
|
||||
e.g.
|
||||
Name => name, Request => request
|
||||
URL => url, METHOD => method, Headers => headers, Data => data
|
||||
"""
|
||||
new_dict = {}
|
||||
if not origin_dict or not isinstance(origin_dict, dict):
|
||||
return origin_dict
|
||||
|
||||
for key, value in origin_dict.items():
|
||||
if depth >= 2:
|
||||
new_dict[key] = value
|
||||
continue
|
||||
|
||||
if isinstance(value, dict):
|
||||
value = lower_dict_key(value, depth+1)
|
||||
|
||||
new_dict[key.lower()] = value
|
||||
|
||||
return new_dict
|
||||
return {
|
||||
key.lower(): value
|
||||
for key, value in origin_dict.items()
|
||||
}
|
||||
|
||||
def lower_config_dict_key(config_dict):
|
||||
""" convert key in config dict to lower case, convertion will occur in two places:
|
||||
1, all keys in config dict;
|
||||
2, all keys in config["request"]
|
||||
"""
|
||||
config_dict = lower_dict_key(config_dict)
|
||||
if "request" in config_dict and isinstance(config_dict["request"], dict):
|
||||
config_dict["request"] = lower_dict_key(config_dict["request"])
|
||||
config_dict = lower_dict_keys(config_dict)
|
||||
if "request" in config_dict:
|
||||
config_dict["request"] = lower_dict_keys(config_dict["request"])
|
||||
|
||||
return config_dict
|
||||
|
||||
|
||||
Reference in New Issue
Block a user