示例#1
0
文件: runner.py 项目: awake006/auto
def format_file_parameter(testcase_id):
    data = {}
    try:
        parameter = global_data.testcase.get(testcase_id)['parameter']
        data = _format_file(parameter, testcase_id)
        global_data.testcase_parameter[testcase_id] = data
        return data
    except (KeyError, FileNotFoundError) as e:
        message_error_format_param = 'The use case [%s] parameter setting is incorrect, please check the parameter file [%s]' % (
            testcase_id, e)
        console_logger.error(message_error_format_param)
        raise e
示例#2
0
 def operate_yaml(self):
     '''
     Convert yaml file to dictionary
     '''
     try:
         with open(self.file, encoding="utf-8") as f:
             result = yaml.load(f)
             result = [i for i in result if i != '']
             return result
     except FileNotFoundError as e:
         console_logger.error(e)
         sys.exit()
示例#3
0
def check_case(testcase, i, number=1):
    schema = TestCaseSchema()
    result_errors = schema.load(testcase).errors
    if result_errors:
        errors_message = 'testcase file-{} case-{} errors-{}'.format(
            i, number, result_errors)
        console_logger.error(errors_message)
        sys.exit()
    if testcase.get('id') in global_data.testcase.keys():
        console_logger.error('file-{} case-{} testcase id {} exist'.format(
            i, number, testcase.get('id')))
        sys.exit()
    global_data.testcase[testcase.get('id')] = testcase
示例#4
0
 def operate_json(self):
     '''
     Convert json file to dictionary
     '''
     try:
         with open(self.file, encoding="utf-8") as f:
             result = json.load(f)
             if isinstance(result, list):
                 result = [i for i in result if i != '']
             return result
     except FileNotFoundError as e:
         console_logger.error(e)
         sys.exit()
示例#5
0
def get_all_yaml(path):
    '''
    Get all yaml files
        @path: folder path
    '''
    try:
        result = [
            os.path.abspath(os.path.join(path, filename))
            for filename in os.listdir(path)
            if filename.split('.')[-1] == "yaml"
            or filename.split('.')[-1] == 'json'
        ]
        return result
    except FileNotFoundError as e:
        console_logger.error(e)
        sys.exit()
示例#6
0
def set_str(n, index):
    '''
    Randomly generate n-bit str
    '''
    try:
        n = int(n)
        source = list(string.ascii_letters) + list(string.digits)
        name = ''
        for _ in range(n):
            name += random.choice(source)
        return name
    except TypeError as e:
        message_error_set_str = 'The use case [%s] parameter setting is incorrect, please check the parameter file [%s]' % (
            index, e)
        console_logger.error(message_error_set_str)
        sys.exit()
示例#7
0
文件: runner.py 项目: awake006/auto
def _format_file(parameter, testcase_id):
    data = {}
    for key in parameter:
        if isinstance(parameter.get(key), dict):
            """
            Dictionary, need to get data from other interfaces
            """
            testcase_dict = parameter.get(key)
            old_case_id = testcase_dict.get('id')
            global_data.testcase_id[testcase_id] = old_case_id
            testcase_result = global_data.testcase_result.get(old_case_id)
            if not testcase_result:
                run(old_case_id)
                testcase_result = global_data.testcase_result.get(old_case_id)
                if not testcase_result:
                    parameter_format_error = '''The use case {} failed to execute,
                     the use case {} parameter could not be built,
                     and the use case was not executed yet.'''.format(
                        old_case_id, testcase_id)
                    console_logger.error(parameter_format_error)
                    raise ParameterFormatException(parameter_format_error)
            if isinstance(testcase_result, list):
                testcase_result = testcase_result[0]
            data[key] = (None,
                         str(testcase_result.get(testcase_dict.get('value'))))
        elif str(parameter.get(key)).split(',')[0] == 'str':
            data[key] = (None,
                         operate_data.set_str(
                             parameter.get(key).split(',')[1], testcase_id))
        elif parameter.get(key) == "random":
            data[key] = (None, str(operate_data.set_time()))

        elif key == "video":
            data[key] = ("video.mp4", open(parameter.get(key),
                                           'rb'), "video/mp4")
        elif key == "img":
            data[key] = ('img.png', open(parameter.get(key),
                                         'rb'), "image/jpg/png/jpeg")
        else:
            data[key] = (None, str(parameter.get(key)))
    return data
示例#8
0
文件: runner.py 项目: awake006/auto
def _format_param(parameter, testcase_id):
    data = {}
    if not isinstance(parameter, dict):
        raise ParameterFormatException('testcase-{} parameter format fail')
    for key in parameter:
        if isinstance(parameter.get(key), dict):
            """
            Dictionary, need to get data from other interfaces
            """
            testcase_dict = parameter.get(key)
            old_case_id = testcase_dict.get('id')
            global_data.testcase_id[testcase_id] = old_case_id
            testcase_result = global_data.testcase_result.get(old_case_id)
            if not testcase_result:
                run(old_case_id)
                testcase_result = global_data.testcase_result.get(old_case_id)
                if not testcase_result:
                    parameter_format_error = '''The use case {} failed to execute,
                     the use case {} parameter could not be built,
                     and the use case was not executed yet.'''.format(
                        old_case_id, testcase_id)
                    console_logger.error(parameter_format_error)
                    raise ParameterFormatException(parameter_format_error)
            if isinstance(testcase_result, list):
                testcase_result = testcase_result[0]
            data[key] = testcase_result.get(testcase_dict.get('value'))
        elif isinstance(parameter.get(key), list):
            data_list = []
            for p in parameter.get(key):
                p_data = _format_param(p, testcase_id)
                data_list.append(p_data)
            data[key] = data_list
        elif str(parameter.get(key)).split(',')[0] == 'str':
            data[key] = operate_data.set_str(
                parameter.get(key).split(',')[1], testcase_id)

        elif parameter.get(key) == "random":
            data[key] = operate_data.set_time()
        else:
            data[key] = parameter.get(key)
    return data
示例#9
0
文件: runner.py 项目: awake006/auto
def format_put_delete(url, testcase_id):
    data = {}
    try:
        parameter = global_data.testcase.get(testcase_id)['parameter']
        for key in parameter:
            if isinstance(parameter.get(key), dict):
                """
                Dictionary, need to get data from other interfaces
                """
                testcase_dict = parameter.get(key)
                old_case_id = testcase_dict.get('id')
                global_data.testcase_id[testcase_id] = old_case_id
                testcase_result = global_data.testcase_result.get(old_case_id)
                if not testcase_result:
                    run(old_case_id)
                    testcase_result = global_data.testcase_result.get(
                        old_case_id)
                    if not testcase_result:
                        parameter_format_error = '''The use case {} failed to execute,
                        the use case {} parameter could not be built,
                        and the use case was not executed yet.'''.format(
                            old_case_id, testcase_id)
                        console_logger.error(parameter_format_error)
                        raise ParameterFormatException(parameter_format_error)
                if isinstance(testcase_result, list):
                    testcase_result = testcase_result[0]
                new_url = url % testcase_result.get(testcase_dict.get('value'))
            elif str(parameter.get(key)).split(',')[0] == 'str':
                data[key] = operate_data.set_str(
                    parameter.get(key).split(',')[1], testcase_id)
            elif parameter.get(key) == "random":
                data[key] = operate_data.set_time()
            else:
                data[key] = parameter.get(key)
        global_data.testcase_parameter[testcase_id] = data
        return new_url, data
    except (KeyError, FileNotFoundError) as e:
        message_error_format_param = 'The use case [%s] parameter setting is incorrect, please check the parameter file [%s]' % (
            testcase_id, e)
        console_logger.error(message_error_format_param)
        raise e