refactor: change variable name from meta_datas to step_datas

This commit is contained in:
debugtalk
2020-04-23 14:59:04 +08:00
parent f6714aff03
commit 3bc124ddff
9 changed files with 20 additions and 51 deletions

View File

@@ -96,4 +96,4 @@ class TestCaseRequestMethodsValidateWithVariables(TestCaseRunner):
if __name__ == '__main__':
runner = TestCaseRequestMethodsValidateWithVariables().run()
print(runner.meta_datas)
print(runner.case_datas)

View File

@@ -70,7 +70,7 @@ class HttpRunner(object):
except exceptions.MyBaseFailure as ex:
self.fail(str(ex))
finally:
self.meta_datas = test_runner.meta_datas
self.step_datas = test_runner.step_datas
if "config" in test_dict:
# run nested testcase

View File

@@ -13,13 +13,13 @@ class HtmlTestResult(unittest.TextTestResult):
self.name = ""
self.status = ""
self.attachment = ""
self.meta_datas = None
self.step_datas = None
def _record_test(self, test, status, attachment=''):
self.name = test.shortDescription()
self.status = status
self.attachment = attachment
self.meta_datas = test.meta_datas
self.step_datas = test.step_datas
def startTestRun(self):
self.start_at = time.time()

View File

@@ -144,43 +144,13 @@ def __stringify_response(response_data):
response_data[key] = value
def __expand_meta_datas(meta_datas, meta_datas_expanded):
""" expand meta_datas to one level
Args:
meta_datas (dict/list): maybe in nested format
Returns:
list: expanded list in one level
Examples:
>>> meta_datas = [
[
dict1,
dict2
],
dict3
]
>>> meta_datas_expanded = []
>>> __expand_meta_datas(meta_datas, meta_datas_expanded)
>>> print(meta_datas_expanded)
[dict1, dict2, dict3]
"""
if isinstance(meta_datas, MetaData):
meta_datas_expanded.append(meta_datas)
elif isinstance(meta_datas, list):
for meta_data in meta_datas:
__expand_meta_datas(meta_data, meta_datas_expanded)
def __get_total_response_time(meta_datas: List[MetaData]):
""" caculate total response time of all meta_datas
def __get_total_response_time(step_datas: List[MetaData]):
""" caculate total response time of all step_datas
"""
try:
response_time = 0
for meta_data in meta_datas:
response_time += meta_data.stat.response_time_ms
for step_data in step_datas:
response_time += step_data.stat.response_time_ms
return "{:.2f}".format(response_time)
@@ -189,10 +159,10 @@ def __get_total_response_time(meta_datas: List[MetaData]):
return "N/A"
def __stringify_meta_datas(meta_datas: List[MetaData]):
def __stringify_meta_datas(step_datas: List[MetaData]):
for meta_data in meta_datas:
data_list = meta_data.data
for step_data in step_datas:
data_list = step_data.data
for data in data_list:
__stringify_request(data["request"])
__stringify_response(data["response"])
@@ -206,6 +176,6 @@ def stringify_summary(testsuite_summary: TestSuiteSummary):
if not testcase_summary.name:
testcase_summary.name = f"testcase {index}"
meta_datas = testcase_summary.meta_datas
__stringify_meta_datas(meta_datas)
testcase_summary.total_response_time = __get_total_response_time(meta_datas)
step_datas = testcase_summary.step_datas
__stringify_meta_datas(step_datas)
testcase_summary.total_response_time = __get_total_response_time(step_datas)

View File

@@ -67,5 +67,5 @@ def get_summary(result: HtmlTestResult) -> TestCaseSummary:
status=result.status,
attachment=result.attachment,
in_out=TestCaseInOut(),
meta_datas=result.meta_datas
step_datas=result.step_datas
)

View File

@@ -63,7 +63,7 @@ class HttpRunner(object):
except exceptions.MyBaseFailure as ex:
self.fail(str(ex))
finally:
self.meta_datas = test_runner.meta_datas
self.step_datas = test_runner.step_datas
test.__doc__ = test_runner.config.name
return test

View File

@@ -13,4 +13,3 @@ class TestHttpRunner(unittest.TestCase):
self.assertTrue(summary.success)
self.assertEqual(summary.details[0].name, "request methods testcase with variables")
self.assertGreater(summary.stat.total, 1)
# self.assertEqual(summary.stat.teststeps["total"], 2)

View File

@@ -15,7 +15,7 @@ class TestCaseRunner(object):
config: TestsConfig = {}
teststeps: List[TestStep] = []
session: HttpSession = None
meta_datas: List[MetaData] = []
step_datas: List[MetaData] = []
validation_results: Dict = {}
def init(self, testcase: TestCase) -> "TestCaseRunner":
@@ -94,13 +94,13 @@ class TestCaseRunner(object):
# save request & response meta data
self.session.meta_data.validators = self.validation_results
self.session.meta_data.name = step.name
self.meta_datas.append(self.session.meta_data)
self.step_datas.append(self.session.meta_data)
return extract_mapping
def test_start(self):
"""main entrance"""
self.meta_datas.clear()
self.step_datas.clear()
session_variables = {}
for step in self.teststeps:
# update with config variables

View File

@@ -114,7 +114,7 @@ class TestCaseSummary(BaseModel):
time: TestCaseTime
in_out: TestCaseInOut = {}
log: Text = ""
meta_datas: List[MetaData] = []
step_datas: List[MetaData] = []
total_response_time: Text = "N/A"