Esempio n. 1
0
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
Esempio n. 2
0
def __extend_with_testcase_ref(raw_testinfo):
    """ extend with test_case reference
    """
    testcase_path = raw_testinfo["test_case"]

    if testcase_path not in tests_def_mapping["testcases"]:
        # make compatible with Windows/Linux
        pwd = get_project_working_directory()
        testcase_path = os.path.join(pwd, *testcase_path.split("/"))
        loaded_testcase = load_file(testcase_path)

        if isinstance(loaded_testcase, list):
            # make compatible with version < 2.2.0
            testcase_dict = load_testcase(loaded_testcase)
        elif isinstance(loaded_testcase,
                        dict) and "teststeps" in loaded_testcase:
            # format version 2, implemented in 2.2.0
            testcase_dict = load_testcase_v2(loaded_testcase)
        else:
            raise exceptions.FileFormatError(
                "Invalid format test_case: {}".format(testcase_path))

        tests_def_mapping["testcases"][testcase_path] = testcase_dict
    else:
        testcase_dict = tests_def_mapping["testcases"][testcase_path]

    raw_testinfo["testcase_def"] = testcase_dict
Esempio n. 3
0
def load_csv_file(csv_file):
    """ load csv file and check file content format
        加载csv文件并检查文件内容格式

    Args:
        csv_file (str): csv file path, csv file content is like below:
        csv文件路径,csv文件内容如下所示

    Returns:
        list: list of parameters, each parameter is in dict format
            参数列表,每个参数都是dict格式

    Examples:
        >>> cat csv_file
        username,password
        test1,111111
        test2,222222
        test3,333333

        >>> load_csv_file(csv_file)
        [
            {'username': '******', 'password': '******'},
            {'username': '******', 'password': '******'},
            {'username': '******', 'password': '******'}
        ]

    """
    if not os.path.isabs(csv_file):
        pwd = get_project_working_directory()
        # make compatible with Windows/Linux 与Windows/Linux兼容
        csv_file = os.path.join(pwd, *csv_file.split("/"))

    if not os.path.isfile(csv_file):
        # file path not exist 文件路径不存在
        raise exceptions.CSVNotFound(csv_file)

    csv_content_list = []

    with io.open(csv_file, encoding='utf-8') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            csv_content_list.append(row)

    return csv_content_list