def get_case_id(self): ''' 获取依赖的case_id :return: ''' data_config = DataConfig(self.data) return data_config.get_depend_case_id()
def write_res(self, res): dc = DataConfig(self.data) sql = settings.UPDATE_RESULT_SQL if res: para = ("pass", self.case_id) else: para = ("fail", self.case_id) dc.write_result(sql, para)
def get_request_field(self): ''' 获取返回的请求字段 :return: ''' data_config = DataConfig(self.data) req_fields = data_config.get_depend_request_field() return json.loads(req_fields)
def get_response_field(self): ''' 获取返回的依赖字段 :return: ''' data_config = DataConfig(self.data) res_fields = data_config.get_depend_response_field() return res_fields and res_fields.split(";")
def get_case_id(self): ''' 获取依赖的case_id,如果有依赖多个case用 | 去分隔 :return: ''' data_config = DataConfig(self.data) case_ids = data_config.get_depend_case_id() case_id_list = case_ids.split("|") return case_id_list
def get_request_field(self): ''' 获取返回的请求字段 :return: ''' data_config = DataConfig(self.data) req_fields = data_config.get_depend_request_field() if req_fields: req_fields_list = req_fields.split("|") return req_fields_list
def write_res(self,res): dc = DataConfig(self.data) sql = settings.UPDATE_RESULT_SQL if res: para = ("pass", self.case_id) self.logger.info("将结果写入数据库,结果为pass") else: para = ("fail", self.case_id) self.logger.error("将结果写入数据库,结果为fail,case_id为{}".format(self.case_id)) dc.write_result(sql,para)
def get_response_field(self): ''' 获取返回的依赖字段,如果有依赖多个case用 | 去分隔 :return: ''' data_config = DataConfig(self.data) res_fields = data_config.get_depend_response_field() # if res_fields: res_fields_list = res_fields.split("|") return [res_fields.split(";") for res_fields in res_fields_list] # ;用于分隔多个字段
def post_act(self): ''' 数据清理操作 :return: ''' dc = DataConfig(self.data) self.post_action = dc.get_post_action() self.post_params = dc.get_post_params() if self.post_action or self.depend_case_id: post_act_obj = PostAct(self.post_action,self.post_params,self.depend_case_id,self.url) post_act_obj.handle_post_action()
def run_main(self): while self.is_run: res = self.run_main_iter() if self.retry_count < 2 and res.status_code >= 500: # 如果在重试次数范围内,返回的是服务器错误,则继续重试 self.retry_count += 1 print("重试第{}次".format(self.retry_count)) self.logger.warn("重试第{}次".format(self.retry_count)) elif self.retry_count >= 2 and res.status_code >= 500: #如果重试到最后,返回的还是服务器错误,则认为其失败,终止循环 r = False break else: # try: print("返回结果: " + str(res.json())) self.logger.info("返回结果:{}".format(res.json())) if self.save_value: HandleSaveValue().save_response_data(res.json(),self.save_value) dc = DataConfig(self.data) r1 = r2 = r3 = True self.expect_for_db = dc.get_expect_for_db() self.expect_for_other = dc.get_expect_for_other() if self.expect_for_db: # 如果只传了sql语句,说明想与返回结果对比 if len(self.expect_for_db) == 1: r1 = self.cmp.compare(self.expect_for_db[0], res.json()) self.logger.info("返回结果与数据库查询结果进行对比,对比结果是{}".format(r1)) else: # 如果传了两个参数,则前面是sql语句,后面是希望sql查询出的结果 r1 = self.cmp.compare(self.expect_for_db[0], self.expect_for_db[1]) self.logger.info("数据库预期结果与数据库查询结果进行对比,对比结果是{}".format(r1)) # 如果传了expect_for_other则会做与接口的返回结果对比 if self.expect_for_other: # 与接口返回结果对比 r2 = self.cmp.compare(self.expect_for_other[0], res.json()) self.logger.info("预期接口返回结果与实际接口返回结果进行对比,对比结果是{}".format(r2)) if len(self.expect_for_other) == 2: # 如果传了第二个参数则要判断文件是否存在 r3 = self.cmp.compare(self.expect_for_other[1]) self.logger.info("判断文件是否存在,对比结果是{}".format(r3)) r = r1 and r2 and r3 break # except Exception as e: # print("发生了未知错误: {}".format(e)) # self.logger.error("发生了未知错误: {}".format(e)) # r = False # break if self.is_run: if res and self.is_write: # oc.write_cookie(res) self.ot.write_token(res.json()) self.write_res(r) return r
def get_request_data(self, clear_interface_data): '''获取当前case的数据''' data_config = DataConfig(clear_interface_data) self.clear_url = data_config.get_url() self.clear_method = data_config.get_method() self.clear_header = data_config.get_header() self.clear_post_action = data_config.get_post_action() self.clear_post_params = data_config.get_post_params() self.depend_case_id = data_config.get_depend_case_id()
def get_field(self): ''' 获取依赖接口的字段 :return: ''' line_data = self.get_line_data() data_config = DataConfig(line_data) self.url = data_config.get_url() self.method = data_config.get_method() self.has_cookie = data_config.has_cookie() self.header = data_config.get_header() self.request_data = data_config.get_params()
def get_request_data(self): data_config = DataConfig(self.data) params = data_config.get_data() return params
def get_field(self, depend_case_id): ''' 获取依赖接口的字段 :return: ''' self.line_data = self.get_line_data(depend_case_id) data_config = DataConfig(self.line_data) self.url = data_config.get_url() self.method = data_config.get_method() self.has_cookie = data_config.has_cookie() self.header = data_config.get_header() self.request_param = data_config.get_param() self.request_data = data_config.get_data() self.request_file = data_config.get_file() self.depend_case_id = data_config.get_depend_case_id() self.save_value = data_config.get_save_value()
def get_request_data(self): '''获取当前case的数据''' data_config = DataConfig(self.data) params = data_config.get_data() return params
def get_field(self): dc = DataConfig(self.data) self.case_id = dc.get_case_id() self.url = dc.get_url() self.method = dc.get_method() self.is_write = dc.is_write() self.is_run = dc.get_is_run() self.has_cookie = dc.has_cookie() self.header = dc.get_header() self.request_param = dc.get_param() self.request_data = dc.get_data() self.request_file = dc.get_file() self.depend_case_id = dc.get_depend_case_id() self.save_value = dc.get_save_value()
def get_field(self): dc = DataConfig(self.data) self.case_id = dc.get_case_id() self.url = dc.get_url() self.method = dc.get_method() self.is_write = dc.is_write() self.is_run = dc.get_is_run() self.has_cookie = dc.has_cookie() self.header = dc.get_header() self.request_param = dc.get_param() self.request_data = dc.get_data() self.request_file = dc.get_file() self.depend_case_id = dc.get_depend_case_id() self.expect = dc.get_expect_for_db() self.post_action = dc.get_post_action() self.post_params = dc.get_post_params()