def __extend_with_api_ref(raw_testinfo): """ extend with api reference Raises: exceptions.ApiNotFound: api not found """ api_name = raw_testinfo["api"] # api maybe defined in two types: # 1, individual file: each file is corresponding to one api definition # 2, api sets file: one file contains a list of api definitions if not os.path.isabs(api_name): # make compatible with Windows/Linux pwd = get_project_working_directory() api_path = os.path.join(pwd, *api_name.split("/")) if os.path.isfile(api_path): # type 1: api is defined in individual file api_name = api_path if api_name in tests_def_mapping["api"]: block = tests_def_mapping["api"][api_name] elif not os.path.isfile(api_name): raise exceptions.ApiNotFound("{} not found!".format(api_name)) else: block = load_file(api_name) # NOTICE: avoid project_mapping been changed during iteration. raw_testinfo["api_def"] = utils.deepcopy_dict(block) tests_def_mapping["api"][api_name] = block
def _get_test_definition(name, ref_type): """ get expected api or testcase. Args: name (str): api or testcase name ref_type (enum): "def-api" or "def-testcase" Returns: dict: expected api/testcase info if found. Raises: exceptions.ApiNotFound: api not found exceptions.TestcaseNotFound: testcase not found """ block = project_mapping.get(ref_type, {}).get(name) if not block: err_msg = "{} not found!".format(name) if ref_type == "def-api": raise exceptions.ApiNotFound(err_msg) else: # ref_type == "def-testcase": raise exceptions.TestcaseNotFound(err_msg) return block
def _get_test_definition(name, ref_type): """ get expected api or suite. @params: name: api or suite name ref_type: "api" or "suite" @return expected api info if found, otherwise raise ApiNotFound exception """ block = TestcaseLoader.overall_def_dict.get(ref_type, {}).get(name) if not block: err_msg = "{} not found!".format(name) if ref_type == "api": raise exceptions.ApiNotFound(err_msg) else: # ref_type == "suite": raise exceptions.SuiteNotFound(err_msg) return block
def _get_test_definition(name, ref_type): ''' get expected api or testcase. Args: name (str): specified api or testcase name ref_type (enum): "def-api" or "testcase" Returns: dict: expected api/testcase info if found. Raises: exceptions.ApiNotFound: api not found exceptions.TestcaseNotFound: testcase not found ''' block = project_mapping.get(ref_type, {}).get(name) if not block: err_msg = f'{name} not found!' if ref_type == 'def-api': logger.log_error(err_msg) raise exceptions.ApiNotFound(err_msg) else: logger.log_error(err_msg) raise exceptions.TestcaseNotFound(err_msg) return block