def test_get_block_by_name(self): loader._load_test_dependencies() ref_call = "get_user($uid, $token)" block = loader._get_block_by_name(ref_call, "api") self.assertEqual(block["request"]["url"], "/api/users/$uid") self.assertEqual(block["function_meta"]["func_name"], "get_user") self.assertEqual(block["function_meta"]["args"], ['$uid', '$token'])
def test_get_test_definition_suite(self): loader._load_test_dependencies() api_def = loader._get_test_definition("create_and_check", "suite") self.assertEqual(api_def["config"]["name"], "create user and check result.") with self.assertRaises(exceptions.TestcaseNotFound): loader._get_test_definition("create_and_check_XXX", "suite")
def test_load_test_file_testcase(self): loader._load_test_dependencies() testset = loader._load_test_file("tests/testcases/smoketest.yml") self.assertEqual(testset["config"]["name"], "smoketest") self.assertEqual(testset["config"]["path"], "tests/testcases/smoketest.yml") self.assertIn("device_sn", testset["config"]["variables"][0]) self.assertEqual(len(testset["testcases"]), 8) self.assertEqual(testset["testcases"][0]["name"], "get token")
def test_get_test_definition_api(self): loader._load_test_dependencies() api_def = loader._get_test_definition("get_headers", "api") self.assertEqual(api_def["request"]["url"], "/headers") self.assertEqual(len(api_def["setup_hooks"]), 2) self.assertEqual(len(api_def["teardown_hooks"]), 1) with self.assertRaises(exceptions.ApiNotFound): loader._get_test_definition("get_token_XXX", "api")
def test_load_testcases_by_path_layered(self): loader._load_test_dependencies() path = os.path.join( os.getcwd(), 'tests/data/demo_testset_layer.yml') testsets_list = loader.load_testcases(path) self.assertIn("variables", testsets_list[0]["config"]) self.assertIn("request", testsets_list[0]["config"]) self.assertIn("request", testsets_list[0]["testcases"][0]) self.assertIn("url", testsets_list[0]["testcases"][0]["request"]) self.assertIn("validate", testsets_list[0]["testcases"][0])
def test_load_testcases_by_path_folder(self): loader._load_test_dependencies() # absolute folder path path = os.path.join(os.getcwd(), 'tests/data') testset_list_1 = loader.load_testcases(path) self.assertGreater(len(testset_list_1), 4) # relative folder path path = 'tests/data/' testset_list_2 = loader.load_testcases(path) self.assertEqual(len(testset_list_1), len(testset_list_2)) # list/set container with file(s) path = [ os.path.join(os.getcwd(), 'tests/data'), 'tests/data/' ] testset_list_3 = loader.load_testcases(path) self.assertEqual(len(testset_list_3), 2 * len(testset_list_1))
def test_override_block(self): loader._load_test_dependencies() def_block = loader._get_block_by_name("get_token($user_agent, $device_sn, $os_platform, $app_version)", "api") test_block = { "name": "override block", "variables": [ {"var": 123} ], 'request': { 'url': '/api/get-token', 'method': 'POST', 'headers': {'user_agent': '$user_agent', 'device_sn': '$device_sn', 'os_platform': '$os_platform', 'app_version': '$app_version'}, 'json': {'sign': '${get_sign($user_agent, $device_sn, $os_platform, $app_version)}'}}, 'validate': [ {'eq': ['status_code', 201]}, {'len_eq': ['content.token', 32]} ] } loader._override_block(def_block, test_block) self.assertEqual(test_block["name"], "override block") self.assertIn({'check': 'status_code', 'expect': 201, 'comparator': 'eq'}, test_block["validate"]) self.assertIn({'check': 'content.token', 'comparator': 'len_eq', 'expect': 32}, test_block["validate"])
def test_get_block_by_name_args_mismatch(self): loader._load_test_dependencies() ref_call = "get_user($uid, $token, $var)" with self.assertRaises(exceptions.ParamsError): loader._get_block_by_name(ref_call, "api")
def test_load_test_dependencies(self): loader._load_test_dependencies() overall_def_dict = loader.overall_def_dict self.assertIn("get_token", overall_def_dict["api"]) self.assertIn("create_and_check", overall_def_dict["suite"])