예제 #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_rows_data(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.dataconfig.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)
		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]
예제 #2
0
class DependdentData:
    # 通过caseID获取其整行数据
    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, case_id):
        rows_data = self.opera_excel.get_rows_data(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)
        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()
        print("----------》")
        print(type(depend_data))
        print(depend_data)
        print(type(response_data))
        print(response_data)
        # 需要jsonpath_rw,解析为json格式
        json_exe = parse(depend_data)
        # 在相应数数据里面去寻找指定的key对应的值
        madle = json_exe.find(response_data)
        # 相当于for i in madle
        return [math.value for math in madle][0]
예제 #3
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()
예제 #4
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()

    #程序执行的
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        #10  0,1,2,3
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_request_url(i)
                method = self.data.get_request_method(i)
                request_data = self.data.get_data_for_json(i)
                expect = self.data.get_expcet_data_for_mysql(i)
                header = self.data.is_header(i)
                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    self.depend_data = DependdentData(depend_case)
                    #获取的依赖响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_field(i)
                    request_data[depend_key] = depend_response_data
                if header == 'write':
                    res = self.run_method.run_main(method, url, request_data)
                    op_header = OperationHeader(res)
                    op_header.write_cookie()

                elif header == 'yes':
                    op_json = OperetionJson('../dataconfig/cookie.json')
                    cookie = op_json.get_data('apsid')
                    cookies = {'apsid': cookie}
                    res = self.run_method.run_main(method, url, request_data,
                                                   cookies)
                else:
                    res = self.run_method.run_main(method, url, request_data)

                if self.com_util.is_equal_dict(expect, res) == 0:
                    self.data.write_result(i, 'pass')
                    pass_count.append(i)
                else:
                    self.data.write_result(i, res)
                    fail_count.append(i)
        self.send_mai.send_main(pass_count, fail_count)
예제 #5
0
	def __init__(self,case_id):
		self.case_id = case_id
		self.opera_excel = OperationExcel()
		self.data = GetData()
예제 #6
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util=CommonUtil()

    def go_on_run(self):
        # 获取case的行数
        rows_count = self.data.get_case_lines()
        print(rows_count)
        for i in range(1,rows_count):
            # 获取需要的列的内容
            is_run=self.data.get_is_run(i)
            if is_run:
                url=self.data.get_request_url(i)
                method=self.data.get_request_method(i)

                request_data=self.data.get_data_for_json(i)
                expect=self.data.get_expcet_data(i)
                header=self.data.is_header(i)
                depend_case=self.data.is_depend(i)
                if depend_case!=None:
                    self.depend_data=DependdentData(depend_case)
                    # 获取依赖响应的数据【依赖case里面的数据】
                    depend_response_data=self.depend_data.get_data_for_key(i)
                    # 获取依赖的key
                    depend_key=self.data.get_depend_field(i)
                    # 更新请求数据里面的内容
                    request_data[depend_key]=depend_response_data
                res=self.run_method.run_main(method,url,request_data,header)
                print(res)
                if self.com_util.is_contain(expect,res):
                    print("测试通过")
                    self.data.write_result(i,"pass")
                else:
                    print("测试失败")
                    self.data.write_result(i,res)