mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix #64: when headers in test is None, it should inherit from config
This commit is contained in:
@@ -155,10 +155,16 @@ def deep_update_dict(origin_dict, override_dict):
|
||||
override_dict = {'b': {'c': 3}}
|
||||
return: {'a': 1, 'b': {'c': 3, 'd': 4}}
|
||||
"""
|
||||
if not override_dict:
|
||||
return origin_dict
|
||||
|
||||
for key, val in override_dict.items():
|
||||
if isinstance(val, dict):
|
||||
tmp = deep_update_dict(origin_dict.get(key, {}), val)
|
||||
origin_dict[key] = tmp
|
||||
elif val is None:
|
||||
# fix #64: when headers in test is None, it should inherit from config
|
||||
continue
|
||||
else:
|
||||
origin_dict[key] = override_dict[key]
|
||||
|
||||
|
||||
13
tests/data/test_bugfix.yml
Normal file
13
tests/data/test_bugfix.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
- config:
|
||||
name: "bugfix testcases."
|
||||
request:
|
||||
base_url: http://127.0.0.1:5000
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
|
||||
- test:
|
||||
name: get headers from config
|
||||
request:
|
||||
url: /api/users/1000
|
||||
method: GET
|
||||
headers:
|
||||
@@ -1,8 +1,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from httprunner import exception, runner, testcase
|
||||
|
||||
from httprunner import exception, runner, testcase, utils
|
||||
from tests.base import ApiServerUnittest
|
||||
|
||||
|
||||
@@ -132,3 +131,16 @@ class TestRunner(ApiServerUnittest):
|
||||
result = self.test_runner.run(testcase_file_path, variables_mapping)
|
||||
self.assertTrue(result["success"])
|
||||
self.assertIn("token", result["output"])
|
||||
|
||||
def test_run_testcase_with_empty_header(self):
|
||||
testcase_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/test_bugfix.yml')
|
||||
testsets = testcase.load_testcases_by_path(testcase_file_path)
|
||||
testset = testsets[0]
|
||||
config_dict_headers = testset["config"]["request"]["headers"]
|
||||
test_dict_headers = testset["testcases"][0]["request"]["headers"]
|
||||
headers = utils.deep_update_dict(
|
||||
config_dict_headers,
|
||||
test_dict_headers
|
||||
)
|
||||
self.assertEqual(headers["Content-Type"], "application/json")
|
||||
|
||||
@@ -163,12 +163,12 @@ class TestUtils(ApiServerUnittest):
|
||||
functions_mapping["endswith"](12345, 45)
|
||||
|
||||
def test_deep_update_dict(self):
|
||||
origin_dict = {'a': 1, 'b': {'c': 3, 'd': 4}, 'f': 6}
|
||||
override_dict = {'a': 2, 'b': {'c': 33, 'e': 5}, 'g': 7}
|
||||
origin_dict = {'a': 1, 'b': {'c': 3, 'd': 4}, 'f': 6, 'h': 123}
|
||||
override_dict = {'a': 2, 'b': {'c': 33, 'e': 5}, 'g': 7, 'h': None}
|
||||
updated_dict = utils.deep_update_dict(origin_dict, override_dict)
|
||||
self.assertEqual(
|
||||
updated_dict,
|
||||
{'a': 2, 'b': {'c': 33, 'd': 4, 'e': 5}, 'f': 6, 'g': 7}
|
||||
{'a': 2, 'b': {'c': 33, 'd': 4, 'e': 5}, 'f': 6, 'g': 7, 'h': 123}
|
||||
)
|
||||
|
||||
def test_get_imported_module(self):
|
||||
|
||||
Reference in New Issue
Block a user