mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
rename teststeps to tests
This commit is contained in:
@@ -38,12 +38,12 @@ class HttpRunner(object):
|
||||
unittest.TestSuite()
|
||||
|
||||
"""
|
||||
def _add_teststep(test_runner, teststep_dict):
|
||||
""" add teststep to testcase.
|
||||
def _add_test(test_runner, test_dict):
|
||||
""" add test to testcase.
|
||||
"""
|
||||
def test(self):
|
||||
try:
|
||||
test_runner.run_test(teststep_dict)
|
||||
test_runner.run_test(test_dict)
|
||||
except exceptions.MyBaseFailure as ex:
|
||||
self.fail(str(ex))
|
||||
finally:
|
||||
@@ -53,7 +53,7 @@ class HttpRunner(object):
|
||||
test_runner.http_client_session.init_meta_data()
|
||||
|
||||
# TODO: refactor
|
||||
test.__doc__ = teststep_dict.get("name") or teststep_dict.get("config", {}).get("name")
|
||||
test.__doc__ = test_dict.get("name") or test_dict.get("config", {}).get("name")
|
||||
return test
|
||||
|
||||
test_suite = unittest.TestSuite()
|
||||
@@ -64,18 +64,18 @@ class HttpRunner(object):
|
||||
test_runner = runner.Runner(config, functions, self.http_client_session)
|
||||
TestSequense = type('TestSequense', (unittest.TestCase,), {})
|
||||
|
||||
teststeps = testcase.get("teststeps", [])
|
||||
for index, teststep_dict in enumerate(teststeps):
|
||||
for times_index in range(int(teststep_dict.get("times", 1))):
|
||||
tests = testcase.get("tests", [])
|
||||
for index, test_dict in enumerate(tests):
|
||||
for times_index in range(int(test_dict.get("times", 1))):
|
||||
# suppose one testcase should not have more than 9999 steps,
|
||||
# and one step should not run more than 999 times.
|
||||
test_method_name = 'test_{:04}_{:03}'.format(index, times_index)
|
||||
test_method = _add_teststep(test_runner, teststep_dict)
|
||||
test_method = _add_test(test_runner, test_dict)
|
||||
setattr(TestSequense, test_method_name, test_method)
|
||||
|
||||
loaded_testcase = self.test_loader.loadTestsFromTestCase(TestSequense)
|
||||
setattr(loaded_testcase, "config", config)
|
||||
setattr(loaded_testcase, "teststeps", teststeps)
|
||||
setattr(loaded_testcase, "tests", tests)
|
||||
setattr(loaded_testcase, "runner", test_runner)
|
||||
test_suite.addTest(loaded_testcase)
|
||||
|
||||
@@ -221,7 +221,7 @@ def prepare_locust_tests(path):
|
||||
|
||||
functions = tests_mapping.get("project_mapping", {}).get("functions", {})
|
||||
testcase = tests_mapping["testcases"][0]
|
||||
items = testcase.get("teststeps", [])
|
||||
items = testcase.get("tests", [])
|
||||
|
||||
tests = []
|
||||
for item in items:
|
||||
|
||||
@@ -17,11 +17,11 @@ class SessionContext(object):
|
||||
def __init__(self, functions, variables=None):
|
||||
self.session_variables_mapping = utils.ensure_mapping_format(variables or {})
|
||||
self.FUNCTIONS_MAPPING = functions
|
||||
self.teststep_variables_mapping = {}
|
||||
self.init_teststep_variables()
|
||||
self.test_variables_mapping = {}
|
||||
self.init_test_variables()
|
||||
|
||||
def init_teststep_variables(self, variables_mapping=None):
|
||||
""" init teststep variables, called when each teststep(api) starts.
|
||||
def init_test_variables(self, variables_mapping=None):
|
||||
""" init test variables, called when each test(api) starts.
|
||||
variables_mapping will be evaluated first.
|
||||
|
||||
Args:
|
||||
@@ -38,14 +38,14 @@ class SessionContext(object):
|
||||
variables_mapping = utils.ensure_mapping_format(variables_mapping)
|
||||
for variable_name, variable_value in variables_mapping.items():
|
||||
variable_value = self.eval_content(variable_value)
|
||||
self.update_teststep_variables(variable_name, variable_value)
|
||||
self.update_test_variables(variable_name, variable_value)
|
||||
|
||||
self.teststep_variables_mapping.update(self.session_variables_mapping)
|
||||
self.test_variables_mapping.update(self.session_variables_mapping)
|
||||
|
||||
def update_teststep_variables(self, variable_name, variable_value):
|
||||
""" update teststep variables, these variables are only valid in the current teststep.
|
||||
def update_test_variables(self, variable_name, variable_value):
|
||||
""" update test variables, these variables are only valid in the current test.
|
||||
"""
|
||||
self.teststep_variables_mapping[variable_name] = variable_value
|
||||
self.test_variables_mapping[variable_name] = variable_value
|
||||
|
||||
def update_seesion_variables(self, variables_mapping):
|
||||
""" update session with extracted variables mapping.
|
||||
@@ -53,7 +53,7 @@ class SessionContext(object):
|
||||
"""
|
||||
variables_mapping = utils.ensure_mapping_format(variables_mapping)
|
||||
self.session_variables_mapping.update(variables_mapping)
|
||||
self.teststep_variables_mapping.update(self.session_variables_mapping)
|
||||
self.test_variables_mapping.update(self.session_variables_mapping)
|
||||
|
||||
def eval_content(self, content):
|
||||
""" evaluate content recursively, take effect on each variable and function in content.
|
||||
@@ -61,7 +61,7 @@ class SessionContext(object):
|
||||
"""
|
||||
return parser.parse_data(
|
||||
content,
|
||||
self.teststep_variables_mapping,
|
||||
self.test_variables_mapping,
|
||||
self.FUNCTIONS_MAPPING
|
||||
)
|
||||
|
||||
|
||||
@@ -279,11 +279,11 @@ tests_def_mapping = {
|
||||
"testcases": {}
|
||||
}
|
||||
|
||||
def load_teststep(raw_stepinfo):
|
||||
""" load teststep with api/testcase/proc references
|
||||
def load_test(raw_testinfo):
|
||||
""" load test with api/testcase/proc references
|
||||
|
||||
Args:
|
||||
raw_stepinfo (dict): teststep data, maybe in 3 formats.
|
||||
raw_testinfo (dict): test data, maybe in 3 formats.
|
||||
# api reference
|
||||
{
|
||||
"name": "add product to cart",
|
||||
@@ -308,24 +308,24 @@ def load_teststep(raw_stepinfo):
|
||||
}
|
||||
|
||||
Returns:
|
||||
list: loaded teststeps list
|
||||
list: loaded tests list
|
||||
|
||||
Args:
|
||||
raw_stepinfo (dict): teststep info
|
||||
raw_testinfo (dict): test info
|
||||
|
||||
"""
|
||||
# reference api
|
||||
if "api" in raw_stepinfo:
|
||||
api_name = raw_stepinfo["api"]
|
||||
raw_stepinfo["api_def"] = _get_api_definition(api_name)
|
||||
if "api" in raw_testinfo:
|
||||
api_name = raw_testinfo["api"]
|
||||
raw_testinfo["api_def"] = _get_api_definition(api_name)
|
||||
|
||||
# TODO: reference proc functions
|
||||
elif "func" in raw_stepinfo:
|
||||
elif "func" in raw_testinfo:
|
||||
pass
|
||||
|
||||
# reference testcase
|
||||
elif "testcase" in raw_stepinfo:
|
||||
testcase_path = raw_stepinfo["testcase"]
|
||||
elif "testcase" in raw_testinfo:
|
||||
testcase_path = raw_testinfo["testcase"]
|
||||
|
||||
if testcase_path not in tests_def_mapping["testcases"]:
|
||||
testcase_path = os.path.join(
|
||||
@@ -337,13 +337,13 @@ def load_teststep(raw_stepinfo):
|
||||
else:
|
||||
testcase_dict = tests_def_mapping[testcase_path]
|
||||
|
||||
raw_stepinfo["testcase_def"] = testcase_dict
|
||||
raw_testinfo["testcase_def"] = testcase_dict
|
||||
|
||||
# define directly
|
||||
else:
|
||||
pass
|
||||
|
||||
return raw_stepinfo
|
||||
return raw_testinfo
|
||||
|
||||
|
||||
def load_testcase(raw_testcase):
|
||||
@@ -360,7 +360,7 @@ def load_testcase(raw_testcase):
|
||||
"request": {}
|
||||
}
|
||||
},
|
||||
# teststeps part
|
||||
# tests part
|
||||
{
|
||||
"test": {...}
|
||||
},
|
||||
@@ -374,12 +374,12 @@ def load_testcase(raw_testcase):
|
||||
{
|
||||
"name": "XYZ",
|
||||
"config": {},
|
||||
"teststeps": [teststep11, teststep12]
|
||||
"tests": [test11, test12]
|
||||
}
|
||||
|
||||
"""
|
||||
config = {}
|
||||
teststeps = []
|
||||
tests = []
|
||||
|
||||
for item in raw_testcase:
|
||||
# TODO: add json schema validation
|
||||
@@ -394,7 +394,7 @@ def load_testcase(raw_testcase):
|
||||
config.update(test_block)
|
||||
|
||||
elif key == "test":
|
||||
teststeps.append(load_teststep(test_block))
|
||||
tests.append(load_test(test_block))
|
||||
|
||||
else:
|
||||
logger.log_warning(
|
||||
@@ -403,7 +403,7 @@ def load_testcase(raw_testcase):
|
||||
|
||||
return {
|
||||
"config": config,
|
||||
"teststeps": teststeps
|
||||
"tests": tests
|
||||
}
|
||||
|
||||
|
||||
@@ -601,16 +601,16 @@ def load_tests(path, dot_env_path=None):
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
"tests": [
|
||||
# test data structure
|
||||
{
|
||||
'name': 'test step desc1',
|
||||
'name': 'test desc1',
|
||||
'variables': [], # optional
|
||||
'extract': [], # optional
|
||||
'validate': [],
|
||||
'request': {}
|
||||
},
|
||||
teststep2 # another teststep dict
|
||||
test_dict_2 # another test dict
|
||||
]
|
||||
},
|
||||
testcase_dict_2 # another testcase dict
|
||||
|
||||
@@ -542,15 +542,15 @@ def parse_data(content, variables_mapping=None, functions_mapping=None):
|
||||
return content
|
||||
|
||||
|
||||
def _extend_with_api(teststep_dict, api_def_dict):
|
||||
""" extend teststep with api definition, teststep will merge and override api definition.
|
||||
def _extend_with_api(test_dict, api_def_dict):
|
||||
""" extend test with api definition, test will merge and override api definition.
|
||||
|
||||
Args:
|
||||
teststep_dict (dict): teststep block
|
||||
test_dict (dict): test block
|
||||
api_def_dict (dict): api definition
|
||||
|
||||
Returns:
|
||||
dict: extended teststep dict.
|
||||
dict: extended test dict.
|
||||
|
||||
Examples:
|
||||
>>> api_def_dict = {
|
||||
@@ -558,12 +558,12 @@ def _extend_with_api(teststep_dict, api_def_dict):
|
||||
"request": {...},
|
||||
"validate": [{'eq': ['status_code', 200]}]
|
||||
}
|
||||
>>> teststep_dict = {
|
||||
>>> test_dict = {
|
||||
"name": "get token 2",
|
||||
"extract": [{"token": "content.token"}],
|
||||
"validate": [{'eq': ['status_code', 201]}, {'len_eq': ['content.token', 16]}]
|
||||
}
|
||||
>>> _extend_with_api(teststep_dict, api_def_dict)
|
||||
>>> _extend_with_api(test_dict, api_def_dict)
|
||||
{
|
||||
"name": "get token 2",
|
||||
"request": {...},
|
||||
@@ -574,18 +574,18 @@ def _extend_with_api(teststep_dict, api_def_dict):
|
||||
"""
|
||||
# override name
|
||||
api_def_name = api_def_dict.pop("name", "")
|
||||
teststep_dict["name"] = teststep_dict.get("name") or api_def_name
|
||||
test_dict["name"] = test_dict.get("name") or api_def_name
|
||||
|
||||
# override variables
|
||||
def_variables = api_def_dict.pop("variables", [])
|
||||
teststep_dict["variables"] = utils.extend_variables(
|
||||
test_dict["variables"] = utils.extend_variables(
|
||||
def_variables,
|
||||
teststep_dict.get("variables", {})
|
||||
test_dict.get("variables", {})
|
||||
)
|
||||
|
||||
# merge & override validators TODO: relocate
|
||||
def_raw_validators = api_def_dict.pop("validate", [])
|
||||
ref_raw_validators = teststep_dict.get("validate", [])
|
||||
ref_raw_validators = test_dict.get("validate", [])
|
||||
def_validators = [
|
||||
parse_validator(validator)
|
||||
for validator in def_raw_validators
|
||||
@@ -594,86 +594,86 @@ def _extend_with_api(teststep_dict, api_def_dict):
|
||||
parse_validator(validator)
|
||||
for validator in ref_raw_validators
|
||||
]
|
||||
teststep_dict["validate"] = utils.extend_validators(
|
||||
test_dict["validate"] = utils.extend_validators(
|
||||
def_validators,
|
||||
ref_validators
|
||||
)
|
||||
|
||||
# merge & override extractors
|
||||
def_extrators = api_def_dict.pop("extract", [])
|
||||
teststep_dict["extract"] = utils.extend_variables(
|
||||
test_dict["extract"] = utils.extend_variables(
|
||||
def_extrators,
|
||||
teststep_dict.get("extract", [])
|
||||
test_dict.get("extract", [])
|
||||
)
|
||||
|
||||
# TODO: merge & override request
|
||||
teststep_dict["request"] = api_def_dict.pop("request", {})
|
||||
test_dict["request"] = api_def_dict.pop("request", {})
|
||||
# base_url
|
||||
if "base_url" in teststep_dict:
|
||||
base_url = teststep_dict.pop("base_url")
|
||||
teststep_dict["request"]["url"] = utils.build_url(
|
||||
if "base_url" in test_dict:
|
||||
base_url = test_dict.pop("base_url")
|
||||
test_dict["request"]["url"] = utils.build_url(
|
||||
base_url,
|
||||
teststep_dict["request"]["url"]
|
||||
test_dict["request"]["url"]
|
||||
)
|
||||
|
||||
# verify
|
||||
if "verify" in teststep_dict:
|
||||
verify = teststep_dict.pop("verify")
|
||||
if "verify" in test_dict:
|
||||
verify = test_dict.pop("verify")
|
||||
elif "verify" in api_def_dict:
|
||||
verify = api_def_dict.pop("verify")
|
||||
else:
|
||||
verify = True
|
||||
teststep_dict["request"]["verify"] = verify
|
||||
test_dict["request"]["verify"] = verify
|
||||
|
||||
# merge & override setup_hooks
|
||||
def_setup_hooks = api_def_dict.pop("setup_hooks", [])
|
||||
ref_setup_hooks = teststep_dict.get("setup_hooks", [])
|
||||
ref_setup_hooks = test_dict.get("setup_hooks", [])
|
||||
extended_setup_hooks = list(set(def_setup_hooks + ref_setup_hooks))
|
||||
if extended_setup_hooks:
|
||||
teststep_dict["setup_hooks"] = extended_setup_hooks
|
||||
test_dict["setup_hooks"] = extended_setup_hooks
|
||||
# merge & override teardown_hooks
|
||||
def_teardown_hooks = api_def_dict.pop("teardown_hooks", [])
|
||||
ref_teardown_hooks = teststep_dict.get("teardown_hooks", [])
|
||||
ref_teardown_hooks = test_dict.get("teardown_hooks", [])
|
||||
extended_teardown_hooks = list(set(def_teardown_hooks + ref_teardown_hooks))
|
||||
if extended_teardown_hooks:
|
||||
teststep_dict["teardown_hooks"] = extended_teardown_hooks
|
||||
test_dict["teardown_hooks"] = extended_teardown_hooks
|
||||
|
||||
# TODO: extend with other api definition items, e.g. times
|
||||
teststep_dict.update(api_def_dict)
|
||||
test_dict.update(api_def_dict)
|
||||
|
||||
return teststep_dict
|
||||
return test_dict
|
||||
|
||||
|
||||
def _extend_with_testcase(teststep_dict, testcase_def_dict):
|
||||
""" extend teststep with testcase definition
|
||||
teststep will merge and override testcase config definition.
|
||||
def _extend_with_testcase(test_dict, testcase_def_dict):
|
||||
""" extend test with testcase definition
|
||||
test will merge and override testcase config definition.
|
||||
|
||||
Args:
|
||||
teststep_dict (dict): teststep block
|
||||
test_dict (dict): test block
|
||||
testcase_def_dict (dict): testcase definition
|
||||
|
||||
Returns:
|
||||
dict: extended teststep dict.
|
||||
dict: extended test dict.
|
||||
|
||||
"""
|
||||
# override testcase config variables
|
||||
testcase_def_dict["config"].setdefault("variables", {})
|
||||
testcase_def_variables = utils.ensure_mapping_format(testcase_def_dict["config"].get("variables", {}))
|
||||
testcase_def_variables.update(teststep_dict.pop("variables", {}))
|
||||
testcase_def_variables.update(test_dict.pop("variables", {}))
|
||||
testcase_def_dict["config"]["variables"] = testcase_def_variables
|
||||
|
||||
# override base_url, verify
|
||||
# priority: testcase config > testsuite teststep
|
||||
teststep_base_url = teststep_dict.pop("base_url", None)
|
||||
teststep_verify = teststep_dict.pop("verify", True)
|
||||
testcase_def_dict["config"].setdefault("base_url", teststep_base_url)
|
||||
testcase_def_dict["config"].setdefault("verify", teststep_verify)
|
||||
# priority: testcase config > testsuite tests
|
||||
test_base_url = test_dict.pop("base_url", None)
|
||||
test_verify = test_dict.pop("verify", True)
|
||||
testcase_def_dict["config"].setdefault("base_url", test_base_url)
|
||||
testcase_def_dict["config"].setdefault("verify", test_verify)
|
||||
|
||||
# override testcase config name, output, etc.
|
||||
testcase_def_dict["config"].update(teststep_dict)
|
||||
testcase_def_dict["config"].update(test_dict)
|
||||
|
||||
teststep_dict.clear()
|
||||
teststep_dict.update(testcase_def_dict)
|
||||
test_dict.clear()
|
||||
test_dict.update(testcase_def_dict)
|
||||
|
||||
|
||||
def __parse_config(config, project_mapping):
|
||||
@@ -722,22 +722,22 @@ def __parse_config(config, project_mapping):
|
||||
)
|
||||
|
||||
|
||||
def __parse_teststeps(teststeps, config, project_mapping):
|
||||
""" override teststeps with testcase config variables, base_url and verify.
|
||||
teststep maybe nested testcase.
|
||||
def __parse_tests(tests, config, project_mapping):
|
||||
""" override tests with testcase config variables, base_url and verify.
|
||||
test maybe nested testcase.
|
||||
|
||||
variables priority:
|
||||
testsuite config > testsuite teststep > testcase config > testcase teststep > api
|
||||
testsuite config > testsuite test > testcase config > testcase test > api
|
||||
|
||||
base_url/verify priority:
|
||||
testcase teststep > testcase config > testsuite teststep > testsuite config > api
|
||||
testcase test > testcase config > testsuite test > testsuite config > api
|
||||
|
||||
Args:
|
||||
teststeps (list):
|
||||
tests (list):
|
||||
config (dict):
|
||||
|
||||
Returns:
|
||||
list: overrided teststeps
|
||||
list: overrided tests
|
||||
|
||||
"""
|
||||
config_variables = config.pop("variables", {})
|
||||
@@ -745,80 +745,80 @@ def __parse_teststeps(teststeps, config, project_mapping):
|
||||
config_verify = config.pop("verify", True)
|
||||
functions = project_mapping.get("functions", {})
|
||||
|
||||
for teststep in teststeps:
|
||||
for test_dict in tests:
|
||||
|
||||
# base_url & verify: priority teststep > config
|
||||
# base_url & verify: priority test_dict > config
|
||||
if config_base_url:
|
||||
teststep.setdefault("base_url", config_base_url)
|
||||
teststep.setdefault("verify", config_verify)
|
||||
test_dict.setdefault("base_url", config_base_url)
|
||||
test_dict.setdefault("verify", config_verify)
|
||||
|
||||
if "testcase_def" in teststep:
|
||||
# teststep is nested testcase
|
||||
if "testcase_def" in test_dict:
|
||||
# test_dict is nested testcase
|
||||
|
||||
# 1, testsuite config => testsuite teststeps
|
||||
# override teststep variables
|
||||
teststep["variables"] = utils.extend_variables(
|
||||
teststep.pop("variables", {}),
|
||||
# 1, testsuite config => testsuite tests
|
||||
# override test_dict variables
|
||||
test_dict["variables"] = utils.extend_variables(
|
||||
test_dict.pop("variables", {}),
|
||||
config_variables
|
||||
)
|
||||
|
||||
# parse teststep name
|
||||
# parse test_dict name
|
||||
try:
|
||||
teststep["name"] = parse_data(
|
||||
teststep.pop("name", ""),
|
||||
teststep["variables"],
|
||||
test_dict["name"] = parse_data(
|
||||
test_dict.pop("name", ""),
|
||||
test_dict["variables"],
|
||||
functions
|
||||
)
|
||||
except exceptions.VariableNotFound:
|
||||
pass
|
||||
|
||||
# 2, testsuite teststep => testcase config
|
||||
testcase_def = teststep.pop("testcase_def")
|
||||
_extend_with_testcase(teststep, testcase_def)
|
||||
# 2, testsuite test_dict => testcase config
|
||||
testcase_def = test_dict.pop("testcase_def")
|
||||
_extend_with_testcase(test_dict, testcase_def)
|
||||
|
||||
# 3, testcase config => testcase teststep
|
||||
_parse_testcase(teststep, project_mapping)
|
||||
# 3, testcase config => testcase test_dict
|
||||
_parse_testcase(test_dict, project_mapping)
|
||||
|
||||
else:
|
||||
# teststep is API test, has two cases.
|
||||
# (1) teststep has API reference
|
||||
# (2) teststep is defined directly
|
||||
# test_dict is API test, has two cases.
|
||||
# (1) test_dict has API reference
|
||||
# (2) test_dict is defined directly
|
||||
|
||||
# 1, config => teststeps
|
||||
# override teststep variables
|
||||
teststep["variables"] = utils.extend_variables(
|
||||
teststep.pop("variables", {}),
|
||||
# 1, config => tests
|
||||
# override test_dict variables
|
||||
test_dict["variables"] = utils.extend_variables(
|
||||
test_dict.pop("variables", {}),
|
||||
config_variables
|
||||
)
|
||||
|
||||
# parse teststep name
|
||||
# parse test_dict name
|
||||
try:
|
||||
teststep["name"] = parse_data(
|
||||
teststep.pop("name", ""),
|
||||
teststep["variables"],
|
||||
test_dict["name"] = parse_data(
|
||||
test_dict.pop("name", ""),
|
||||
test_dict["variables"],
|
||||
functions
|
||||
)
|
||||
except exceptions.VariableNotFound:
|
||||
pass
|
||||
|
||||
if "api_def" in teststep:
|
||||
if "api_def" in test_dict:
|
||||
# case (1)
|
||||
# 2, teststep => api
|
||||
api_def_dict = teststep.pop("api_def")
|
||||
_extend_with_api(teststep, api_def_dict)
|
||||
# 2, test_dict => api
|
||||
api_def_dict = test_dict.pop("api_def")
|
||||
_extend_with_api(test_dict, api_def_dict)
|
||||
else:
|
||||
# case (2)
|
||||
if "base_url" in teststep:
|
||||
base_url = teststep.pop("base_url")
|
||||
teststep["request"]["url"] = utils.build_url(
|
||||
if "base_url" in test_dict:
|
||||
base_url = test_dict.pop("base_url")
|
||||
test_dict["request"]["url"] = utils.build_url(
|
||||
base_url,
|
||||
teststep["request"]["url"]
|
||||
test_dict["request"]["url"]
|
||||
)
|
||||
|
||||
|
||||
def _parse_testcase(testcase, project_mapping):
|
||||
__parse_config(testcase["config"], project_mapping)
|
||||
__parse_teststeps(testcase["teststeps"], testcase["config"], project_mapping)
|
||||
__parse_tests(testcase["tests"], testcase["config"], project_mapping)
|
||||
|
||||
|
||||
def parse_tests(tests_mapping):
|
||||
@@ -841,8 +841,8 @@ def parse_tests(tests_mapping):
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional, priority 2
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
"tests": [
|
||||
# test data structure
|
||||
{
|
||||
'name': 'test step desc1',
|
||||
'variables': [], # optional, priority 3
|
||||
@@ -853,7 +853,7 @@ def parse_tests(tests_mapping):
|
||||
'request': {},
|
||||
}
|
||||
},
|
||||
teststep2 # another teststep dict
|
||||
test_dict_2 # another test dict
|
||||
]
|
||||
},
|
||||
testcase_dict_2 # another testcase dict
|
||||
|
||||
@@ -19,15 +19,15 @@ class Runner(object):
|
||||
}
|
||||
>>> runner = Runner(config, functions)
|
||||
|
||||
>>> teststep = {
|
||||
"name": "teststep description",
|
||||
>>> test_dict = {
|
||||
"name": "test description",
|
||||
"variables": [], # optional
|
||||
"request": {
|
||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||
"method": "GET"
|
||||
}
|
||||
}
|
||||
>>> runner.run_test(teststep)
|
||||
>>> runner.run_test(test_dict)
|
||||
|
||||
"""
|
||||
|
||||
@@ -68,32 +68,32 @@ class Runner(object):
|
||||
if self.testcase_teardown_hooks:
|
||||
self.do_hook_actions(self.testcase_teardown_hooks)
|
||||
|
||||
def _handle_skip_feature(self, teststep_dict):
|
||||
""" handle skip feature for teststep
|
||||
def _handle_skip_feature(self, test_dict):
|
||||
""" handle skip feature for test
|
||||
- skip: skip current test unconditionally
|
||||
- skipIf: skip current test if condition is true
|
||||
- skipUnless: skip current test unless condition is true
|
||||
|
||||
Args:
|
||||
teststep_dict (dict): teststep info
|
||||
test_dict (dict): test info
|
||||
|
||||
Raises:
|
||||
SkipTest: skip teststep
|
||||
SkipTest: skip test
|
||||
|
||||
"""
|
||||
# TODO: move skip to initialize
|
||||
skip_reason = None
|
||||
|
||||
if "skip" in teststep_dict:
|
||||
skip_reason = teststep_dict["skip"]
|
||||
if "skip" in test_dict:
|
||||
skip_reason = test_dict["skip"]
|
||||
|
||||
elif "skipIf" in teststep_dict:
|
||||
skip_if_condition = teststep_dict["skipIf"]
|
||||
elif "skipIf" in test_dict:
|
||||
skip_if_condition = test_dict["skipIf"]
|
||||
if self.session_context.eval_content(skip_if_condition):
|
||||
skip_reason = "{} evaluate to True".format(skip_if_condition)
|
||||
|
||||
elif "skipUnless" in teststep_dict:
|
||||
skip_unless_condition = teststep_dict["skipUnless"]
|
||||
elif "skipUnless" in test_dict:
|
||||
skip_unless_condition = test_dict["skipUnless"]
|
||||
if not self.session_context.eval_content(skip_unless_condition):
|
||||
skip_reason = "{} evaluate to False".format(skip_unless_condition)
|
||||
|
||||
@@ -106,11 +106,11 @@ class Runner(object):
|
||||
# TODO: check hook function if valid
|
||||
self.session_context.eval_content(action)
|
||||
|
||||
def _run_teststep(self, teststep_dict):
|
||||
def _run_test(self, test_dict):
|
||||
""" run single teststep.
|
||||
|
||||
Args:
|
||||
teststep_dict (dict): teststep info
|
||||
test_dict (dict): teststep info
|
||||
{
|
||||
"name": "teststep description",
|
||||
"skip": "skip this test unconditionally",
|
||||
@@ -139,28 +139,28 @@ class Runner(object):
|
||||
|
||||
"""
|
||||
# check skip
|
||||
self._handle_skip_feature(teststep_dict)
|
||||
self._handle_skip_feature(test_dict)
|
||||
|
||||
# prepare
|
||||
teststep_dict = utils.lower_test_dict_keys(teststep_dict)
|
||||
teststep_variables = teststep_dict.get("variables", {})
|
||||
self.session_context.init_teststep_variables(teststep_variables)
|
||||
test_dict = utils.lower_test_dict_keys(test_dict)
|
||||
test_variables = test_dict.get("variables", {})
|
||||
self.session_context.init_test_variables(test_variables)
|
||||
|
||||
# parse teststep request
|
||||
raw_request = teststep_dict.get('request', {})
|
||||
parsed_teststep_request = self.session_context.eval_content(raw_request)
|
||||
self.session_context.update_teststep_variables("request", parsed_teststep_request)
|
||||
# parse test request
|
||||
raw_request = test_dict.get('request', {})
|
||||
parsed_test_request = self.session_context.eval_content(raw_request)
|
||||
self.session_context.update_test_variables("request", parsed_test_request)
|
||||
|
||||
# setup hooks
|
||||
setup_hooks = teststep_dict.get("setup_hooks", [])
|
||||
setup_hooks = test_dict.get("setup_hooks", [])
|
||||
setup_hooks.insert(0, "${setup_hook_prepare_kwargs($request)}")
|
||||
self.do_hook_actions(setup_hooks)
|
||||
|
||||
try:
|
||||
url = parsed_teststep_request.pop('url')
|
||||
method = parsed_teststep_request.pop('method')
|
||||
parsed_teststep_request.setdefault("verify", self.verify)
|
||||
group_name = parsed_teststep_request.pop("group", None)
|
||||
url = parsed_test_request.pop('url')
|
||||
method = parsed_test_request.pop('method')
|
||||
parsed_test_request.setdefault("verify", self.verify)
|
||||
group_name = parsed_test_request.pop("group", None)
|
||||
except KeyError:
|
||||
raise exceptions.ParamsError("URL or METHOD missed!")
|
||||
|
||||
@@ -173,38 +173,38 @@ class Runner(object):
|
||||
raise exceptions.ParamsError(err_msg)
|
||||
|
||||
logger.log_info("{method} {url}".format(method=method, url=url))
|
||||
logger.log_debug("request kwargs(raw): {kwargs}".format(kwargs=parsed_teststep_request))
|
||||
logger.log_debug("request kwargs(raw): {kwargs}".format(kwargs=parsed_test_request))
|
||||
|
||||
# request
|
||||
resp = self.http_client_session.request(
|
||||
method,
|
||||
url,
|
||||
name=group_name,
|
||||
**parsed_teststep_request
|
||||
**parsed_test_request
|
||||
)
|
||||
resp_obj = response.ResponseObject(resp)
|
||||
|
||||
# teardown hooks
|
||||
teardown_hooks = teststep_dict.get("teardown_hooks", [])
|
||||
teardown_hooks = test_dict.get("teardown_hooks", [])
|
||||
if teardown_hooks:
|
||||
logger.log_info("start to run teardown hooks")
|
||||
self.session_context.update_teststep_variables("response", resp_obj)
|
||||
self.session_context.update_test_variables("response", resp_obj)
|
||||
self.do_hook_actions(teardown_hooks)
|
||||
|
||||
# extract
|
||||
extractors = teststep_dict.get("extract", [])
|
||||
extractors = test_dict.get("extract", [])
|
||||
extracted_variables_mapping = resp_obj.extract_response(extractors)
|
||||
self.session_context.update_seesion_variables(extracted_variables_mapping)
|
||||
|
||||
# validate
|
||||
validators = teststep_dict.get("validate", [])
|
||||
validators = test_dict.get("validate", [])
|
||||
try:
|
||||
self.evaluated_validators = self.session_context.validate(validators, resp_obj)
|
||||
except (exceptions.ParamsError, exceptions.ValidationFailure, exceptions.ExtractFailure):
|
||||
# log request
|
||||
err_req_msg = "request: \n"
|
||||
err_req_msg += "headers: {}\n".format(parsed_teststep_request.pop("headers", {}))
|
||||
for k, v in parsed_teststep_request.items():
|
||||
err_req_msg += "headers: {}\n".format(parsed_test_request.pop("headers", {}))
|
||||
for k, v in parsed_test_request.items():
|
||||
err_req_msg += "{}: {}\n".format(k, repr(v))
|
||||
logger.log_error(err_req_msg)
|
||||
|
||||
@@ -223,18 +223,18 @@ class Runner(object):
|
||||
config = testcase_dict.get("config", {})
|
||||
test_runner = Runner(config, self.functions, self.http_client_session)
|
||||
|
||||
teststeps = testcase_dict.get("teststeps", [])
|
||||
for index, teststep_dict in enumerate(teststeps):
|
||||
test_runner.run_test(teststep_dict)
|
||||
tests = testcase_dict.get("tests", [])
|
||||
for index, test_dict in enumerate(tests):
|
||||
test_runner.run_test(test_dict)
|
||||
|
||||
self.session_context.update_seesion_variables(test_runner.extract_sessions())
|
||||
|
||||
def run_test(self, teststep_dict):
|
||||
def run_test(self, test_dict):
|
||||
""" run single teststep of testcase.
|
||||
teststep_dict may be in 3 types.
|
||||
test_dict may be in 3 types.
|
||||
|
||||
Args:
|
||||
teststep_dict (dict):
|
||||
test_dict (dict):
|
||||
|
||||
# teststep
|
||||
{
|
||||
@@ -249,7 +249,7 @@ class Runner(object):
|
||||
# embeded testcase
|
||||
{
|
||||
"config": {...},
|
||||
"teststeps": [
|
||||
"tests": [
|
||||
{...},
|
||||
{...}
|
||||
]
|
||||
@@ -262,11 +262,11 @@ class Runner(object):
|
||||
}
|
||||
|
||||
"""
|
||||
if "config" in teststep_dict:
|
||||
self._run_testcase(teststep_dict)
|
||||
if "config" in test_dict:
|
||||
self._run_testcase(test_dict)
|
||||
else:
|
||||
# api
|
||||
self._run_teststep(teststep_dict)
|
||||
self._run_test(test_dict)
|
||||
|
||||
def extract_sessions(self):
|
||||
"""
|
||||
|
||||
@@ -19,9 +19,9 @@ def is_testcase(data_structure):
|
||||
"variables": [], # optional
|
||||
"request": {} # optional
|
||||
},
|
||||
"teststeps": [
|
||||
teststep1,
|
||||
{ # teststep2
|
||||
"tests": [
|
||||
test_dict1,
|
||||
{ # test_dict2
|
||||
'name': 'test step desc2',
|
||||
'variables': [], # optional
|
||||
'extract': [], # optional
|
||||
@@ -40,10 +40,10 @@ def is_testcase(data_structure):
|
||||
if not isinstance(data_structure, dict):
|
||||
return False
|
||||
|
||||
if "teststeps" not in data_structure:
|
||||
if "tests" not in data_structure:
|
||||
return False
|
||||
|
||||
if not isinstance(data_structure["teststeps"], list):
|
||||
if not isinstance(data_structure["tests"], list):
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -67,8 +67,8 @@ def is_testcases(data_structure):
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
"tests": [
|
||||
# test data structure
|
||||
{
|
||||
'name': 'test step desc1',
|
||||
'variables': [], # optional
|
||||
@@ -76,7 +76,7 @@ def is_testcases(data_structure):
|
||||
'validate': [],
|
||||
'request': {}
|
||||
},
|
||||
teststep2 # another teststep dict
|
||||
test_dict_2 # another test dict
|
||||
]
|
||||
},
|
||||
testcase_dict_2 # another testcase dict
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
},
|
||||
'variables': []
|
||||
},
|
||||
'teststeps': [
|
||||
'tests': [
|
||||
{
|
||||
'name': '/api/get-token',
|
||||
'request': {
|
||||
@@ -119,7 +119,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
},
|
||||
'variables': []
|
||||
},
|
||||
"teststeps": [
|
||||
"tests": [
|
||||
{
|
||||
"name": "post data",
|
||||
"request": {
|
||||
@@ -182,7 +182,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
testcases = [
|
||||
{
|
||||
"config": {"name": "test teardown hooks"},
|
||||
"teststeps": [
|
||||
"tests": [
|
||||
{
|
||||
"name": "test teardown hooks",
|
||||
"request": {
|
||||
@@ -222,7 +222,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
"config": {
|
||||
"name": "test teardown hooks"
|
||||
},
|
||||
"teststeps": [
|
||||
"tests": [
|
||||
{
|
||||
"name": "test teardown hooks",
|
||||
"request": {
|
||||
@@ -256,7 +256,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
"config": {
|
||||
"name": "test teardown hooks"
|
||||
},
|
||||
"teststeps": [
|
||||
"tests": [
|
||||
{
|
||||
"name": "test teardown hooks",
|
||||
"request": {
|
||||
@@ -368,28 +368,28 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
test_suite = runner._add_tests(tests_mapping)
|
||||
|
||||
self.assertEqual(
|
||||
test_suite._tests[0].teststeps[0]['name'],
|
||||
test_suite._tests[0].tests[0]['name'],
|
||||
'get token with iOS/10.1 and test1'
|
||||
)
|
||||
# TODO: add parameterize
|
||||
# self.assertEqual(
|
||||
# test_suite._tests[1].teststeps[0]['name'],
|
||||
# test_suite._tests[1].tests[0]['name'],
|
||||
# 'get token with iOS/10.1 and test2'
|
||||
# )
|
||||
# self.assertEqual(
|
||||
# test_suite._tests[2].teststeps[0]['name'],
|
||||
# test_suite._tests[2].tests[0]['name'],
|
||||
# 'get token with iOS/10.2 and test1'
|
||||
# )
|
||||
# self.assertEqual(
|
||||
# test_suite._tests[3].teststeps[0]['name'],
|
||||
# test_suite._tests[3].tests[0]['name'],
|
||||
# 'get token with iOS/10.2 and test2'
|
||||
# )
|
||||
# self.assertEqual(
|
||||
# test_suite._tests[4].teststeps[0]['name'],
|
||||
# test_suite._tests[4].tests[0]['name'],
|
||||
# 'get token with iOS/10.3 and test1'
|
||||
# )
|
||||
# self.assertEqual(
|
||||
# test_suite._tests[5].teststeps[0]['name'],
|
||||
# test_suite._tests[5].tests[0]['name'],
|
||||
# 'get token with iOS/10.3 and test2'
|
||||
# )
|
||||
|
||||
@@ -419,13 +419,13 @@ class TestApi(ApiServerUnittest):
|
||||
self.assertEqual(testcase_config["name"], "setup and reset all.")
|
||||
self.assertIn("path", testcase_config)
|
||||
|
||||
testcase_teststeps = testcases[0]["teststeps"]
|
||||
self.assertEqual(len(testcase_teststeps), 2)
|
||||
self.assertIn("api", testcase_teststeps[0])
|
||||
self.assertEqual(testcase_teststeps[0]["name"], "get token (setup)")
|
||||
self.assertIsInstance(testcase_teststeps[0]["variables"], list)
|
||||
self.assertIn("api_def", testcase_teststeps[0])
|
||||
self.assertEqual(testcase_teststeps[0]["api_def"]["request"]["url"], "/api/get-token")
|
||||
testcase_tests = testcases[0]["tests"]
|
||||
self.assertEqual(len(testcase_tests), 2)
|
||||
self.assertIn("api", testcase_tests[0])
|
||||
self.assertEqual(testcase_tests[0]["name"], "get token (setup)")
|
||||
self.assertIsInstance(testcase_tests[0]["variables"], list)
|
||||
self.assertIn("api_def", testcase_tests[0])
|
||||
self.assertEqual(testcase_tests[0]["api_def"]["request"]["url"], "/api/get-token")
|
||||
|
||||
def test_testcase_parser(self):
|
||||
testcase_path = "tests/testcases/setup.yml"
|
||||
@@ -437,13 +437,13 @@ class TestApi(ApiServerUnittest):
|
||||
self.assertEqual(len(parsed_testcases), 1)
|
||||
|
||||
self.assertNotIn("variables", parsed_testcases[0]["config"])
|
||||
self.assertEqual(len(parsed_testcases[0]["teststeps"]), 2)
|
||||
self.assertEqual(len(parsed_testcases[0]["tests"]), 2)
|
||||
|
||||
teststep1 = parsed_testcases[0]["teststeps"][0]
|
||||
self.assertEqual(teststep1["name"], "get token (setup)")
|
||||
self.assertNotIn("api_def", teststep1)
|
||||
self.assertEqual(teststep1["variables"]["device_sn"], "TESTCASE_SETUP_XXX")
|
||||
self.assertEqual(teststep1["request"]["url"], "http://127.0.0.1:5000/api/get-token")
|
||||
test_dict1 = parsed_testcases[0]["tests"][0]
|
||||
self.assertEqual(test_dict1["name"], "get token (setup)")
|
||||
self.assertNotIn("api_def", test_dict1)
|
||||
self.assertEqual(test_dict1["variables"]["device_sn"], "TESTCASE_SETUP_XXX")
|
||||
self.assertEqual(test_dict1["request"]["url"], "http://127.0.0.1:5000/api/get-token")
|
||||
|
||||
def test_testcase_add_tests(self):
|
||||
testcase_path = "tests/testcases/setup.yml"
|
||||
@@ -454,10 +454,10 @@ class TestApi(ApiServerUnittest):
|
||||
test_suite = runner._add_tests(tests_mapping)
|
||||
|
||||
self.assertEqual(len(test_suite._tests), 1)
|
||||
teststeps = test_suite._tests[0].teststeps
|
||||
self.assertEqual(teststeps[0]["name"], "get token (setup)")
|
||||
self.assertEqual(teststeps[0]["variables"]["device_sn"], "TESTCASE_SETUP_XXX")
|
||||
self.assertIn("api", teststeps[0])
|
||||
tests = test_suite._tests[0].tests
|
||||
self.assertEqual(tests[0]["name"], "get token (setup)")
|
||||
self.assertEqual(tests[0]["variables"]["device_sn"], "TESTCASE_SETUP_XXX")
|
||||
self.assertIn("api", tests[0])
|
||||
|
||||
def test_testcase_simple_run_suite(self):
|
||||
testcase_path = "tests/testcases/setup.yml"
|
||||
@@ -504,14 +504,14 @@ class TestApi(ApiServerUnittest):
|
||||
self.assertEqual(testcase_config["name"], "create users with uid")
|
||||
self.assertIn("path", testcase_config)
|
||||
|
||||
testcase_teststeps = testcases[0]["teststeps"]
|
||||
self.assertEqual(len(testcase_teststeps), 2)
|
||||
self.assertIn("testcase_def", testcase_teststeps[0])
|
||||
self.assertEqual(testcase_teststeps[0]["name"], "create user 1000 and check result.")
|
||||
self.assertIsInstance(testcase_teststeps[0]["testcase_def"], dict)
|
||||
self.assertEqual(testcase_teststeps[0]["testcase_def"]["config"]["name"], "create user and check result.")
|
||||
self.assertEqual(len(testcase_teststeps[0]["testcase_def"]["teststeps"]), 4)
|
||||
self.assertEqual(testcase_teststeps[0]["testcase_def"]["teststeps"][0]["name"], "setup and reset all (override).")
|
||||
testcase_tests = testcases[0]["tests"]
|
||||
self.assertEqual(len(testcase_tests), 2)
|
||||
self.assertIn("testcase_def", testcase_tests[0])
|
||||
self.assertEqual(testcase_tests[0]["name"], "create user 1000 and check result.")
|
||||
self.assertIsInstance(testcase_tests[0]["testcase_def"], dict)
|
||||
self.assertEqual(testcase_tests[0]["testcase_def"]["config"]["name"], "create user and check result.")
|
||||
self.assertEqual(len(testcase_tests[0]["testcase_def"]["tests"]), 4)
|
||||
self.assertEqual(testcase_tests[0]["testcase_def"]["tests"][0]["name"], "setup and reset all (override).")
|
||||
|
||||
def test_testsuite_parser(self):
|
||||
testcase_path = "tests/testsuites/create_users.yml"
|
||||
@@ -521,17 +521,17 @@ class TestApi(ApiServerUnittest):
|
||||
|
||||
parsed_testcases = tests_mapping["testcases"]
|
||||
self.assertEqual(len(parsed_testcases), 1)
|
||||
self.assertEqual(len(parsed_testcases[0]["teststeps"]), 2)
|
||||
self.assertEqual(len(parsed_testcases[0]["tests"]), 2)
|
||||
|
||||
testcase1 = parsed_testcases[0]["teststeps"][0]
|
||||
testcase1 = parsed_testcases[0]["tests"][0]
|
||||
self.assertEqual(testcase1["config"]["name"], "create user 1000 and check result.")
|
||||
self.assertNotIn("testcase_def", testcase1)
|
||||
self.assertEqual(len(testcase1["teststeps"]), 4)
|
||||
self.assertEqual(len(testcase1["tests"]), 4)
|
||||
self.assertEqual(
|
||||
testcase1["teststeps"][0]["teststeps"][0]["request"]["url"],
|
||||
testcase1["tests"][0]["tests"][0]["request"]["url"],
|
||||
"http://127.0.0.1:5000/api/get-token"
|
||||
)
|
||||
self.assertEqual(len(testcase1["teststeps"][0]["teststeps"][0]["variables"]["device_sn"]), 15)
|
||||
self.assertEqual(len(testcase1["tests"][0]["tests"][0]["variables"]["device_sn"]), 15)
|
||||
|
||||
def test_testsuite_add_tests(self):
|
||||
testcase_path = "tests/testsuites/create_users.yml"
|
||||
@@ -542,8 +542,8 @@ class TestApi(ApiServerUnittest):
|
||||
test_suite = runner._add_tests(tests_mapping)
|
||||
|
||||
self.assertEqual(len(test_suite._tests), 1)
|
||||
teststeps = test_suite._tests[0].teststeps
|
||||
self.assertEqual(teststeps[0]["config"]["name"], "create user 1000 and check result.")
|
||||
tests = test_suite._tests[0].tests
|
||||
self.assertEqual(tests[0]["config"]["name"], "create user 1000 and check result.")
|
||||
|
||||
def test_testsuite_run_suite(self):
|
||||
testcase_path = "tests/testsuites/create_users.yml"
|
||||
|
||||
@@ -22,9 +22,9 @@ class TestContext(ApiServerUnittest):
|
||||
context_functions = self.context.FUNCTIONS_MAPPING
|
||||
self.assertIn("gen_md5", context_functions)
|
||||
|
||||
def test_init_teststep_variables(self):
|
||||
def test_init_test_variables(self):
|
||||
self.assertEqual(
|
||||
self.context.teststep_variables_mapping,
|
||||
self.context.test_variables_mapping,
|
||||
{'SECRET_KEY': 'DebugTalk'}
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ class TestContext(ApiServerUnittest):
|
||||
{"data": '{"name": "user", "password": "123456"}'},
|
||||
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
|
||||
]
|
||||
self.context.init_teststep_variables(variables)
|
||||
self.context.init_test_variables(variables)
|
||||
|
||||
request = {
|
||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||
@@ -110,7 +110,7 @@ class TestContext(ApiServerUnittest):
|
||||
{"resp_status_code": 200},
|
||||
{"resp_body_success": True}
|
||||
]
|
||||
self.context.init_teststep_variables(variables)
|
||||
self.context.init_test_variables(variables)
|
||||
|
||||
with self.assertRaises(exceptions.ValidationFailure):
|
||||
self.context.validate(validators, resp_obj)
|
||||
@@ -125,7 +125,7 @@ class TestContext(ApiServerUnittest):
|
||||
{"resp_status_code": 201},
|
||||
{"resp_body_success": True}
|
||||
]
|
||||
self.context.init_teststep_variables(variables)
|
||||
self.context.init_test_variables(variables)
|
||||
self.context.validate(validators, resp_obj)
|
||||
|
||||
def test_validate_exception(self):
|
||||
@@ -139,7 +139,7 @@ class TestContext(ApiServerUnittest):
|
||||
{"check": "$resp_status_code", "comparator": "eq", "expect": 201}
|
||||
]
|
||||
variables = []
|
||||
self.context.init_teststep_variables(variables)
|
||||
self.context.init_test_variables(variables)
|
||||
|
||||
with self.assertRaises(exceptions.VariableNotFound):
|
||||
self.context.validate(validators, resp_obj)
|
||||
@@ -148,7 +148,7 @@ class TestContext(ApiServerUnittest):
|
||||
variables = [
|
||||
{"resp_status_code": 200}
|
||||
]
|
||||
self.context.init_teststep_variables(variables)
|
||||
self.context.init_test_variables(variables)
|
||||
|
||||
with self.assertRaises(exceptions.ValidationFailure):
|
||||
self.context.validate(validators, resp_obj)
|
||||
|
||||
@@ -264,8 +264,8 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
cls.project_mapping = loader.project_mapping
|
||||
cls.tests_def_mapping = loader.tests_def_mapping
|
||||
|
||||
def test_load_teststep_testcase(self):
|
||||
raw_teststep = {
|
||||
def test_load_test_testcase(self):
|
||||
raw_test = {
|
||||
"name": "setup and reset all (override).",
|
||||
"testcase": "testcases/setup.yml",
|
||||
"variables": [
|
||||
@@ -273,24 +273,24 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
],
|
||||
"output": ["token", "device_sn"]
|
||||
}
|
||||
testcase = loader.load_teststep(raw_teststep)
|
||||
testcase = loader.load_test(raw_test)
|
||||
self.assertEqual(
|
||||
"setup and reset all (override).",
|
||||
testcase["name"]
|
||||
)
|
||||
teststeps = testcase["testcase_def"]["teststeps"]
|
||||
self.assertEqual(len(teststeps), 2)
|
||||
self.assertEqual(teststeps[0]["name"], "get token (setup)")
|
||||
self.assertEqual(teststeps[1]["name"], "reset all users")
|
||||
tests = testcase["testcase_def"]["tests"]
|
||||
self.assertEqual(len(tests), 2)
|
||||
self.assertEqual(tests[0]["name"], "get token (setup)")
|
||||
self.assertEqual(tests[1]["name"], "reset all users")
|
||||
|
||||
def test_load_testcase(self):
|
||||
raw_testcase = loader.load_file("tests/testsuites/create_users.yml")
|
||||
testcase = loader.load_testcase(raw_testcase)
|
||||
self.assertEqual(testcase["config"]["name"], "create users with uid")
|
||||
self.assertIn("device_sn", testcase["config"]["variables"][0])
|
||||
self.assertEqual(len(testcase["teststeps"]), 2)
|
||||
self.assertEqual(testcase["teststeps"][0]["name"], "create user 1000 and check result.")
|
||||
self.assertEqual(testcase["teststeps"][0]["testcase_def"]["config"]["name"], "create user and check result.")
|
||||
self.assertEqual(len(testcase["tests"]), 2)
|
||||
self.assertEqual(testcase["tests"][0]["name"], "create user 1000 and check result.")
|
||||
self.assertEqual(testcase["tests"][0]["testcase_def"]["config"]["name"], "create user and check result.")
|
||||
|
||||
def test_load_testcases_by_path_files(self):
|
||||
# absolute file path
|
||||
@@ -300,7 +300,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
project_mapping = tests_mapping["project_mapping"]
|
||||
testcases_list = tests_mapping["testcases"]
|
||||
self.assertEqual(len(testcases_list), 1)
|
||||
self.assertEqual(len(testcases_list[0]["teststeps"]), 3)
|
||||
self.assertEqual(len(testcases_list[0]["tests"]), 3)
|
||||
self.assertIn("get_sign", project_mapping["functions"])
|
||||
|
||||
# relative file path
|
||||
@@ -309,7 +309,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
project_mapping = tests_mapping["project_mapping"]
|
||||
testcases_list = tests_mapping["testcases"]
|
||||
self.assertEqual(len(testcases_list), 1)
|
||||
self.assertEqual(len(testcases_list[0]["teststeps"]), 3)
|
||||
self.assertEqual(len(testcases_list[0]["tests"]), 3)
|
||||
self.assertIn("get_sign", project_mapping["functions"])
|
||||
|
||||
# TODO: list/set container with file(s)
|
||||
@@ -319,17 +319,17 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
# ]
|
||||
# testcases_list = loader.load_tests(path)
|
||||
# self.assertEqual(len(testcases_list), 2)
|
||||
# self.assertEqual(len(testcases_list[0]["teststeps"]), 3)
|
||||
# self.assertEqual(len(testcases_list[1]["teststeps"]), 3)
|
||||
# self.assertEqual(len(testcases_list[0]["tests"]), 3)
|
||||
# self.assertEqual(len(testcases_list[1]["tests"]), 3)
|
||||
# testcases_list.extend(testcases_list)
|
||||
# self.assertEqual(len(testcases_list), 4)
|
||||
|
||||
# for testcase in testcases_list:
|
||||
# for teststep in testcase["teststeps"]:
|
||||
# self.assertIn('name', teststep)
|
||||
# self.assertIn('request', teststep)
|
||||
# self.assertIn('url', teststep['request'])
|
||||
# self.assertIn('method', teststep['request'])
|
||||
# for test_dict in testcase["tests"]:
|
||||
# self.assertIn('name', test_dict)
|
||||
# self.assertIn('request', test_dict)
|
||||
# self.assertIn('url', test_dict['request'])
|
||||
# self.assertIn('method', test_dict['request'])
|
||||
|
||||
def test_load_testcases_by_path_folder(self):
|
||||
# absolute folder path
|
||||
@@ -381,15 +381,15 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
self.assertIn({'device_sn': '${gen_random_string(15)}'}, testcases_list[0]["config"]["variables"])
|
||||
self.assertIn("gen_md5", project_mapping["functions"])
|
||||
self.assertIn("base_url", testcases_list[0]["config"])
|
||||
teststep0 = testcases_list[0]["teststeps"][0]
|
||||
test_dict0 = testcases_list[0]["tests"][0]
|
||||
self.assertEqual(
|
||||
"get token with $user_agent, $app_version",
|
||||
teststep0["name"]
|
||||
test_dict0["name"]
|
||||
)
|
||||
self.assertIn("/api/get-token", teststep0["api_def"]["request"]["url"])
|
||||
self.assertIn("/api/get-token", test_dict0["api_def"]["request"]["url"])
|
||||
self.assertIn(
|
||||
{'eq': ['status_code', 200]},
|
||||
teststep0["validate"]
|
||||
test_dict0["validate"]
|
||||
)
|
||||
|
||||
def test_load_testcases_with_testcase_ref(self):
|
||||
@@ -407,7 +407,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
{'device_sn': '${gen_random_string(15)}'},
|
||||
testcases_list[0]["config"]["variables"][0]
|
||||
)
|
||||
testcase0 = testcases_list[0]["teststeps"][0]
|
||||
testcase0 = testcases_list[0]["tests"][0]
|
||||
self.assertEqual(
|
||||
"create user 1000 and check result.",
|
||||
testcase0["name"]
|
||||
@@ -417,7 +417,7 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
testcase0["testcase_def"]["config"]["name"]
|
||||
)
|
||||
|
||||
testcase1 = testcases_list[0]["teststeps"][1]
|
||||
testcase1 = testcases_list[0]["tests"][1]
|
||||
self.assertEqual(
|
||||
"create user 1001 and check result.",
|
||||
testcase1["name"]
|
||||
|
||||
@@ -445,9 +445,9 @@ class TestParser(unittest.TestCase):
|
||||
parser.parse_tests(tests_mapping)
|
||||
parsed_testcases = tests_mapping["testcases"]
|
||||
self.assertIsInstance(parsed_testcases, list)
|
||||
teststep1 = parsed_testcases[0]["teststeps"][0]
|
||||
self.assertEqual(teststep1["variables"]["var_c"], 3)
|
||||
self.assertEqual(teststep1["variables"]["PROJECT_KEY"], "ABCDEFGH")
|
||||
test_dict1 = parsed_testcases[0]["tests"][0]
|
||||
self.assertEqual(test_dict1["variables"]["var_c"], 3)
|
||||
self.assertEqual(test_dict1["variables"]["PROJECT_KEY"], "ABCDEFGH")
|
||||
# TODO: parameters
|
||||
# self.assertEqual(len(parsed_testcases), 2 * 2)
|
||||
self.assertEqual(parsed_testcases[0]["config"]["name"], '1230')
|
||||
@@ -479,11 +479,11 @@ class TestParser(unittest.TestCase):
|
||||
|
||||
def test_extend_with_api(self):
|
||||
loader.load_project_tests(os.path.join(os.getcwd(), "tests"))
|
||||
raw_stepinfo = {
|
||||
raw_testinfo = {
|
||||
"name": "get token",
|
||||
"api": "get_token",
|
||||
}
|
||||
api_def_dict = loader.load_teststep(raw_stepinfo)
|
||||
api_def_dict = loader.load_test(raw_testinfo)
|
||||
test_block = {
|
||||
"name": "override block",
|
||||
"times": 3,
|
||||
|
||||
@@ -215,7 +215,7 @@ class TestRunner(ApiServerUnittest):
|
||||
tests_mapping = loader.load_tests(testcase_file_path)
|
||||
testcase = tests_mapping["testcases"][0]
|
||||
config_dict_headers = testcase["config"]["request"]["headers"]
|
||||
test_dict_headers = testcase["teststeps"][0]["request"]["headers"]
|
||||
test_dict_headers = testcase["tests"][0]["request"]["headers"]
|
||||
headers = deep_update_dict(
|
||||
config_dict_headers,
|
||||
test_dict_headers
|
||||
|
||||
@@ -24,8 +24,8 @@ class TestValidator(unittest.TestCase):
|
||||
"path": "testcase1_path",
|
||||
"variables": [], # optional
|
||||
},
|
||||
"teststeps": [
|
||||
# teststep data structure
|
||||
"tests": [
|
||||
# test data structure
|
||||
{
|
||||
'name': 'test step desc1',
|
||||
'variables': [], # optional
|
||||
@@ -33,7 +33,7 @@ class TestValidator(unittest.TestCase):
|
||||
'validate': [],
|
||||
'request': {}
|
||||
},
|
||||
# teststep2 # another teststep dict
|
||||
# test_dict2 # another test dict
|
||||
]
|
||||
},
|
||||
# testcase_dict_2 # another testcase dict
|
||||
|
||||
Reference in New Issue
Block a user