lower testcase key

This commit is contained in:
debugtalk
2017-09-13 16:17:21 +08:00
parent 0e601c1865
commit 83bcc27133
5 changed files with 45 additions and 33 deletions

View File

@@ -5,7 +5,6 @@ import sys
from collections import OrderedDict
from ate import utils
from ate.exception import ParamsError
from ate.testcase import TestcaseParser
@@ -135,13 +134,6 @@ class Context(object):
@param request_dict: request config mapping
@param level: testset or testcase
"""
if "headers" in request_dict:
# convert keys in request headers to lowercase
headers = request_dict.pop("headers")
if not isinstance(headers, dict):
raise ParamsError("HTTP Request Headers invalid!")
request_dict["headers"] = {key.lower(): headers[key] for key in headers}
if level == "testset":
request_dict = self.testcase_parser.parse_content_with_bindings(
request_dict

View File

@@ -1,4 +1,4 @@
from ate import exception, response
from ate import exception, response, utils
from ate.client import HttpSession
from ate.context import Context
@@ -48,6 +48,9 @@ class Runner(object):
}
@param (str) context level, testcase or testset
"""
# convert keys in request headers to lowercase
config_dict = utils.lower_dict_key(config_dict)
self.context.init_context(level)
self.context.config_context(config_dict, level)

View File

@@ -329,3 +329,20 @@ def search_conf_item(start_path, item_type, item_name):
raise exception.VariableNotFound(err_msg)
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.
"""
new_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