mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
lower testcase key
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
17
ate/utils.py
17
ate/utils.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user