Ejemplo n.º 1
0
class DependentData:
    def __init__(self, case_id):
        self.opera_excel = OperationExcel()
        self.case_id = case_id
        self.data = GetData()

    # 通过case_id获取case_id的整行数据
    def get_case_line_data(self, case_id):
        rows_data = self.opera_excel.get_rows_data(case_id)
        return rows_data

    # 执行依赖测试,获取结果
    def run_dependent(self):
        run_method = RunMethod()
        row_num = self.opera_excel.get_row_num(self.case_id)
        url = self.data.get_url(row_num)
        data = self.data.get_data_for_json(row_num)
        header = self.data.get_is_header(row_num)
        method = self.data.get_request_method(row_num)
        res = run_method.run_main(method, url, data, header)
        return json.loads(res)

    # 根据依赖的key去获取执行依赖测试case的响应,然后返回
    def get_data_for_key(self, row):
        depend_data = self.data.get_depend_key(row)
        response_data = self.run_dependent()
        json_exe = parse(depend_data)
        madle = json_exe.find(response_data)
        return [math.value for math in madle][0]
Ejemplo n.º 2
0
class DependData(object):
    '''有依赖的case处理模块,case2依赖case1点数据
	'''
    def __init__(self, case_id):
        self.case_id = case_id
        self.opera_excel = OperationExcel()
        self.get_data = GetData()

    # 获取目标行的数据
    def get_case_line_data(self):
        return self.opera_excel.get_rows_data(self.case_id)

    # 执行case1用例返回结果
    def run_denpend(self):
        run_method = RunMain()
        # 执行请求
        row_num = self.opera_excel.get_rows_num(self.case_id) + 1
        # print(row_num)
        request_json = self.get_data.get_data_json(row_num)
        url = self.get_data.get_request_url(row_num)
        # print(url)
        request_method = self.get_data.get_request_method(row_num)
        is_header = self.get_data.get_is_header(row_num)
        res = run_method.run_main(url, request_method, request_json, is_header)
        # 返回请求结果
        return res

    # 在case1用例返回的数据中,拿到case2所需要的字段的数据,返回
    def get_data_key(self, row):
        depend_data_key = self.get_data.get_depend_key(row)
        # print(depend_data_key)
        # 将str数据类型转换为json数据类型(dict字典)
        response_data = json.loads(self.run_denpend())
        # print(type(response_data))
        # 需要在json中匹配的字段规则
        jsonpath_expr = parse(depend_data_key)
        # 在json数据中查找规则字段 返回一个list
        male = jsonpath_expr.find(response_data)
        # 返回需要的对应字段中的内容
        return [match.value for match in male][0]
Ejemplo n.º 3
0
class DependentData:
    def __init__(self, case_id):
        self.case_id = case_id
        self.opera_excel = OperationExcel
        self.data = GetData()

    # 执行依赖测试获取结果
    def run_dependent(self):
        run_method = RunMethod()
        row_num1 = self.opera_excel()
        row_num = row_num1.get_rows_num(self.case_id)
        request_data1 = self.data.get_data_for_json(row_num)
        request_data = json.dumps(request_data1)
        header1 = self.data.is_header(row_num)
        header = eval(header1)
        method = self.data.get_request_method(row_num)
        url = self.data.get_request_url(row_num)
        token = self.data.get_token(row_num)
        if token == 'yes':
            # 获取当前文件路径
            current_path = os.path.abspath(__file__)
            # 获取当前文件的父目录
            father_path = os.path.dirname(current_path)
            path = os.path.join(father_path, "wenjian", "cookie.json")
            op_json = OperationJson(path)
            token = op_json.get_data("access_token")
            tokens = {'Authorization': "Bearer " + token}
            # 将header与token合并
            header = dict(header, **tokens)
        res = run_method.run_main(method, url, request_data, header)
        return json.loads(res)

    # 根据依赖的key去获取执行依赖测试case的响应,然后返回
    def get_data_for_key(self, row):
        depend_data = self.data.get_depend_key(row)
        response_data = self.run_dependent()
        json_exe = parse(depend_data)
        madle = json_exe.find(response_data)
        return [math.value for math in madle][0]