def test_load_yaml_testcases(self): testcase_file_path = os.path.join( os.getcwd(), 'tests/data/demo_testset_hardcode.yml') testcases = utils.load_tests(testcase_file_path) self.assertEqual(len(testcases), 3) testcase = testcases[0]["test"] self.assertIn('name', testcase) self.assertIn('request', testcase) self.assertIn('url', testcase['request']) self.assertIn('method', testcase['request'])
def test_run_single_testcase(self): for testcase_file_path in self.testcase_file_path_list: testcases = utils.load_tests(testcase_file_path) testcase = testcases[0]["test"] self.assertTrue(self.test_runner._run_test(testcase)) testcase = testcases[1]["test"] self.assertTrue(self.test_runner._run_test(testcase)) testcase = testcases[2]["test"] self.assertTrue(self.test_runner._run_test(testcase))
def load_test_file(file_path): """ load testset file, get testset data structure. @param file_path: absolute valid testset file path @return testset dict { "name": "desc1", "config": {}, "api": {}, "testcases": [testcase11, testcase12] } """ testset = { "name": "", "config": { "path": file_path }, "api": {}, "testcases": [] } tests_list = utils.load_tests(file_path) for item in tests_list: for key in item: if key == "config": testset["config"].update(item["config"]) testset["name"] = item["config"].get("name", "") elif key == "test": test_block_dict = item["test"] if "api" in test_block_dict: ref_name = test_block_dict["api"] test_info = get_testinfo_by_reference(ref_name, "api") test_block_dict.update(test_info) testset["testcases"].append(test_block_dict) elif "suite" in test_block_dict: ref_name = test_block_dict["suite"] test_info = get_testinfo_by_reference(ref_name, "suite") testset["testcases"].extend(test_info["testcases"]) else: testset["testcases"].append(test_block_dict) elif key == "api": api_def = item["api"].pop("def") function_meta = parse_function(api_def) func_name = function_meta["func_name"] api_info = {} api_info["function_meta"] = function_meta api_info.update(item["api"]) testset["api"][func_name] = api_info return testset
def test_load_testcases_bad_filepath(self): testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo') self.assertEqual(utils.load_tests(testcase_file_path), [])
def setUp(self): self.context = Context() testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml') self.testcases = utils.load_tests(testcase_file_path)