Example #1
0
class DependdentData:
    def __init__(self, case_id):
        self.case_id = case_id
        self.opera_excel = OperationExcel()
        self.data = GetData()

    """通过case_id去获取该case_id的整行数据"""

    def get_case_line_data(self):
        rows_data = self.opera_excel.get_row_values(self.case_id)
        return rows_data

    #执行依赖测试获取结果
    def run_dependent(self):
        run_method = RunMethod()
        row_num = self.opera_excel.get_row_num(self.case_id)
        request_data = self.data.get_data_for_json(row_num)
        header = self.data.is_header(row_num)
        method = self.data.get_request_method(row_num)
        url = self.data.get_request_url(row_num)
        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]
Example #2
0
class DependData:
    def __init__(self, case_id):
        self.case_id = case_id
        self.oper_excel = OperationExcel()
        self.data = GetData()

    # 通过case_id去获取该case_id的整行数据
    def get_case_line_data(self):
        rows_data = self.oper_excel.get_row_values(self.case_id)

    # 执行所依赖接口,获得结果
    def run_dependent(self):
        run_method = RunMethod()
        rowx = self.oper_excel.get_row_num(self.case_id)
        url = self.data.get_url(rowx)
        # header = self.data.get_header(rowx)
        request_data = self.data.get_request_for_json(rowx)
        method = self.data.get_method_type(rowx)
        res = run_method.run_main(url, method, request_data)
        return res

    # 根据excel中“依赖的返回数据”,查找前置接口运行结果的字段
    def get_data_for_key(self, rowx):
        depend_data = self.data.get_depend_respons(rowx)  # excel中依赖的返回字段
        response_data = self.run_dependent()  # 前置接口运行后的返回结果
        json_exe = parse(depend_data)
        madle = json_exe.find(response_data)
        return [math.value for math in madle]  # 返回匹配的字段值