refactor function and variable name

This commit is contained in:
debugtalk
2018-09-04 17:14:54 +08:00
parent a442b5279e
commit 903005bc84
4 changed files with 23 additions and 24 deletions

View File

@@ -27,7 +27,7 @@ class Runner(object):
self.testcase_teardown_hooks = config_dict.pop("teardown_hooks", [])
self.context = Context(config_variables, config_functions)
self.init_config(config_dict, "testcase")
self.init_test(config_dict, "testcase")
if testcase_setup_hooks:
self.do_hook_actions(testcase_setup_hooks)
@@ -36,11 +36,11 @@ class Runner(object):
if self.testcase_teardown_hooks:
self.do_hook_actions(self.testcase_teardown_hooks)
def init_config(self, config_dict, level):
def init_test(self, test_dict, level):
""" create/update context variables binds
Args:
config_dict (dict):
test_dict (dict):
level (enum): "testcase" or "teststep"
testcase:
{
@@ -73,15 +73,14 @@ class Runner(object):
dict: parsed request dict
"""
# convert keys in request headers to lowercase
config_dict = utils.lower_config_dict_key(config_dict)
test_dict = utils.lower_test_dict_keys(test_dict)
self.context.init_context_variables(level)
variables = config_dict.get('variables') \
or config_dict.get('variable_binds', OrderedDict())
variables = test_dict.get('variables') \
or test_dict.get('variable_binds', OrderedDict())
self.context.update_context_variables(variables, level)
request_config = config_dict.get('request', {})
request_config = test_dict.get('request', {})
parsed_request = self.context.get_parsed_request(request_config, level)
base_url = parsed_request.pop("base_url", None)
@@ -165,7 +164,7 @@ class Runner(object):
# prepare
extractors = teststep_dict.get("extract", []) or teststep_dict.get("extractors", [])
validators = teststep_dict.get("validate", []) or teststep_dict.get("validators", [])
parsed_request = self.init_config(teststep_dict, level="teststep")
parsed_request = self.init_test(teststep_dict, level="teststep")
self.context.update_teststep_variables_mapping("request", parsed_request)
# setup hooks

View File

@@ -162,19 +162,19 @@ def lower_dict_keys(origin_dict):
for key, value in origin_dict.items()
}
def lower_config_dict_key(config_dict):
""" convert key in config dict to lower case, convertion will occur in three places:
1, all keys in config dict;
2, all keys in config["request"]
def lower_test_dict_keys(test_dict):
""" convert keys in test_dict to lower case, convertion will occur in two places:
1, all keys in test_dict;
2, all keys in test_dict["request"]
"""
# convert keys in config dict
config_dict = lower_dict_keys(config_dict)
# convert keys in test_dict
test_dict = lower_dict_keys(test_dict)
if "request" in config_dict:
# convert keys in config["request"]
config_dict["request"] = lower_dict_keys(config_dict["request"])
if "request" in test_dict:
# convert keys in test_dict["request"]
test_dict["request"] = lower_dict_keys(test_dict["request"])
return config_dict
return test_dict
def convert_mappinglist_to_orderdict(mapping_list):
""" convert mapping list to ordered dict

View File

@@ -184,7 +184,7 @@ class TestRunner(ApiServerUnittest):
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"]
}
config_dict = {}
self.test_runner.init_config(config_dict, "testcase")
self.test_runner.init_test(config_dict, "testcase")
start_time = time.time()
self.test_runner.run_test(test)
@@ -215,7 +215,7 @@ class TestRunner(ApiServerUnittest):
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"]
}
config_dict = {}
self.test_runner.init_config(config_dict, "testcase")
self.test_runner.init_test(config_dict, "testcase")
start_time = time.time()
self.test_runner.run_test(test)
@@ -241,7 +241,7 @@ class TestRunner(ApiServerUnittest):
os.getcwd(), 'tests/data/test_bugfix.yml')
testcases = loader.load_file(testcase_file_path)
config_dict = {}
self.test_runner.init_config(config_dict, "testcase")
self.test_runner.init_test(config_dict, "testcase")
test = testcases[2]["test"]
self.test_runner.run_test(test)

View File

@@ -167,7 +167,7 @@ class TestUtils(ApiServerUnittest):
}
}
}
new_dict = utils.lower_config_dict_key(origin_dict)
new_dict = utils.lower_test_dict_keys(origin_dict)
self.assertIn("name", new_dict)
self.assertIn("request", new_dict)
self.assertIn("method", new_dict["request"])
@@ -179,7 +179,7 @@ class TestUtils(ApiServerUnittest):
"Name": "test",
"Request": "$default_request"
}
new_dict = utils.lower_config_dict_key(origin_dict)
new_dict = utils.lower_test_dict_keys(origin_dict)
self.assertIn("$default_request", new_dict["request"])
def test_lower_dict_keys(self):