for method, params in entry_json.items():
request_data_key = "json" ("consumes")[0].startswith("application/json") else "data"            if method.upper() in ["POST", "PUT", "PATCH"]:
for param ("parameters"):
("in") == "body":
schema_obj = ("name")
for obj, properties in self.api_("definitions").items():
data_dict = {}
if obj in schema_obj:
for k, v ("properties").items():
data_dict[k] = f"${k}"
testStep_dict["request"][request_data_key] = data_dict
@staticmethod
def _make_validate(testStep_dict):
testStep_dict["validate"].append({"eq": ["status_code", 200]})
def _prepare_testStep(self, path, entry_json):
testStep_dict = {
"name": "",
"request": {},
"validate": []
}
self._make_request_url(testStep_dict, path)
self._make_request_method(testStep_dict, entry_json)
self._make_request_headers(testStep_dict, entry_json)
self._make_request_params(testStep_dict, entry_json)
self._make_request_data(testStep_dict, entry_json)
self._make_validate(testStep_dict)
return testStep_dict
@staticmethod
def _prepare_config():
return {
"base_url": "${ENV(BASE_URL)}",
"name": "testCase description",
"variables": {}
}
def _prepare_testSteps(self, path, entry_json):
""" make testStep list.
testSteps list are parsed from HAR log entries list.
"""
return [self._prepare_testStep(path, entry_json)]
def _make_testCase(self, path, entry_json):
""" Extract info from HAR file and prepare for testCase
"""
logger.debug("Extract info from HAR file and prepare for testCase.")
config = self._prepare_config()
testSteps = self._prepare_testSteps(path, entry_json)
return {
"config": config,
"testSteps": testSteps
}
python新手代码userid
def gen_testCase(self, path=None, file_type="yml"):
"""
Generate test cases based on the specified path
"""
if path is not None:
for test_mapping in get_target_value(path, self.api_("paths")):
logger.info(f"Start to generate testCase.: {path}")
testCase = self._make_testCase(path, test_mapping)
file = get_file_path(path, test_mapping) + "." + file_type
dump_yaml(testCase, file) if file_type == "yml" else dump_json(testCase, file)
logger.debug("prepared testCase: {}".format(testCase))
else:
for path, test_mapping in self.api_("paths").items():

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。