mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
lower testcase key
This commit is contained in:
@@ -5,7 +5,6 @@ import sys
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from ate import utils
|
from ate import utils
|
||||||
from ate.exception import ParamsError
|
|
||||||
from ate.testcase import TestcaseParser
|
from ate.testcase import TestcaseParser
|
||||||
|
|
||||||
|
|
||||||
@@ -135,13 +134,6 @@ class Context(object):
|
|||||||
@param request_dict: request config mapping
|
@param request_dict: request config mapping
|
||||||
@param level: testset or testcase
|
@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":
|
if level == "testset":
|
||||||
request_dict = self.testcase_parser.parse_content_with_bindings(
|
request_dict = self.testcase_parser.parse_content_with_bindings(
|
||||||
request_dict
|
request_dict
|
||||||
|
|||||||
+4
-1
@@ -1,4 +1,4 @@
|
|||||||
from ate import exception, response
|
from ate import exception, response, utils
|
||||||
from ate.client import HttpSession
|
from ate.client import HttpSession
|
||||||
from ate.context import Context
|
from ate.context import Context
|
||||||
|
|
||||||
@@ -48,6 +48,9 @@ class Runner(object):
|
|||||||
}
|
}
|
||||||
@param (str) context level, testcase or testset
|
@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.init_context(level)
|
||||||
self.context.config_context(config_dict, level)
|
self.context.config_context(config_dict, level)
|
||||||
|
|
||||||
|
|||||||
@@ -329,3 +329,20 @@ def search_conf_item(start_path, item_type, item_name):
|
|||||||
raise exception.VariableNotFound(err_msg)
|
raise exception.VariableNotFound(err_msg)
|
||||||
|
|
||||||
return search_conf_item(dir_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.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|||||||
+4
-24
@@ -178,26 +178,6 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
SECRET_KEY = context_variables["SECRET_KEY"]
|
SECRET_KEY = context_variables["SECRET_KEY"]
|
||||||
self.assertEqual(SECRET_KEY, "DebugTalk")
|
self.assertEqual(SECRET_KEY, "DebugTalk")
|
||||||
|
|
||||||
def test_parse_request(self):
|
|
||||||
request_dict = {
|
|
||||||
"url": "http://debugtalk.com",
|
|
||||||
"method": "GET",
|
|
||||||
"headers": {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"USER-AGENT": "ios/10.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parsed_request = self.context.get_parsed_request(request_dict)
|
|
||||||
self.assertIn("content-type", parsed_request["headers"])
|
|
||||||
self.assertIn("user-agent", parsed_request["headers"])
|
|
||||||
|
|
||||||
request_dict = {
|
|
||||||
"headers": "invalid headers"
|
|
||||||
}
|
|
||||||
with self.assertRaises(ParamsError):
|
|
||||||
self.context.get_parsed_request(request_dict)
|
|
||||||
|
|
||||||
def test_get_parsed_request(self):
|
def test_get_parsed_request(self):
|
||||||
test_runner = runner.Runner()
|
test_runner = runner.Runner()
|
||||||
testcase = {
|
testcase = {
|
||||||
@@ -210,14 +190,14 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
"request": {
|
"request": {
|
||||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||||
"method": "POST",
|
"METHOD": "POST",
|
||||||
"headers": {
|
"Headers": {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"authorization": "$authorization",
|
"authorization": "$authorization",
|
||||||
"random": "$random",
|
"random": "$random",
|
||||||
"SECRET_KEY": "$SECRET_KEY"
|
"SECRET_KEY": "$SECRET_KEY"
|
||||||
},
|
},
|
||||||
"data": "$data"
|
"Data": "$data"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parsed_request = test_runner.init_config(testcase, level="testcase")
|
parsed_request = test_runner.init_config(testcase, level="testcase")
|
||||||
@@ -227,7 +207,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
self.assertEqual(len(parsed_request["headers"]["random"]), 5)
|
self.assertEqual(len(parsed_request["headers"]["random"]), 5)
|
||||||
self.assertIn("data", parsed_request)
|
self.assertIn("data", parsed_request)
|
||||||
self.assertEqual(parsed_request["data"], testcase["variable_binds"][2]["data"])
|
self.assertEqual(parsed_request["data"], testcase["variable_binds"][2]["data"])
|
||||||
self.assertEqual(parsed_request["headers"]["secret_key"], "DebugTalk")
|
self.assertEqual(parsed_request["headers"]["SECRET_KEY"], "DebugTalk")
|
||||||
|
|
||||||
def test_exec_content_functions(self):
|
def test_exec_content_functions(self):
|
||||||
test_runner = runner.Runner()
|
test_runner = runner.Runner()
|
||||||
|
|||||||
@@ -293,3 +293,23 @@ class TestUtils(ApiServerUnittest):
|
|||||||
|
|
||||||
self.assertFalse(utils.is_variable(("os", os)))
|
self.assertFalse(utils.is_variable(("os", os)))
|
||||||
self.assertFalse(utils.is_variable(("utils", utils)))
|
self.assertFalse(utils.is_variable(("utils", utils)))
|
||||||
|
|
||||||
|
def test_lower_dict_key(self):
|
||||||
|
origin_dict = {
|
||||||
|
"Name": "test",
|
||||||
|
"Request": {
|
||||||
|
"url": "http://127.0.0.1:5000",
|
||||||
|
"METHOD": "POST",
|
||||||
|
"Headers": {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"User-Agent": "ios/9.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new_dict = utils.lower_dict_key(origin_dict)
|
||||||
|
self.assertIn("name", new_dict)
|
||||||
|
self.assertIn("request", new_dict)
|
||||||
|
self.assertIn("method", new_dict["request"])
|
||||||
|
self.assertIn("headers", new_dict["request"])
|
||||||
|
self.assertIn("Accept", new_dict["request"]["headers"])
|
||||||
|
self.assertIn("User-Agent", new_dict["request"]["headers"])
|
||||||
|
|||||||
Reference in New Issue
Block a user