mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
convert keys in request headers to lowercase
This commit is contained in:
@@ -6,8 +6,9 @@ import sys
|
||||
import types
|
||||
from collections import OrderedDict
|
||||
|
||||
from ate.testcase import TestcaseParser
|
||||
from ate import utils
|
||||
from ate.exception import ParamsError
|
||||
from ate.testcase import TestcaseParser
|
||||
|
||||
|
||||
def is_function(tup):
|
||||
@@ -114,6 +115,13 @@ class Context(object):
|
||||
self.testcase_parser.bind_functions(self.testcase_functions_config)
|
||||
|
||||
def register_request(self, request_dict, level="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}
|
||||
|
||||
self.__update_context_request_config(level, request_dict)
|
||||
|
||||
def __update_context_request_config(self, level, config_mapping):
|
||||
|
||||
@@ -3,6 +3,7 @@ import unittest
|
||||
|
||||
from ate import utils, runner
|
||||
from ate.context import Context
|
||||
from ate.exception import ParamsError
|
||||
|
||||
|
||||
class VariableBindsUnittest(unittest.TestCase):
|
||||
@@ -159,6 +160,28 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
authorization = context_variables["authorization"]
|
||||
self.assertEqual(utils.gen_md5(TOKEN, data, random), authorization)
|
||||
|
||||
def test_register_request(self):
|
||||
request_dict = {
|
||||
"url": "http://debugtalk.com",
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"Content-Type": "application/json",
|
||||
"USER-AGENT": "ios/10.3"
|
||||
}
|
||||
}
|
||||
self.context.register_request(request_dict)
|
||||
|
||||
parsed_request = self.context.get_parsed_request()
|
||||
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.register_request(request_dict)
|
||||
|
||||
|
||||
def test_get_parsed_request(self):
|
||||
test_runner = runner.Runner()
|
||||
testcase = {
|
||||
|
||||
Reference in New Issue
Block a user