コード例 #1
0
 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
コード例 #2
0
ファイル: send_main.py プロジェクト: jiangll888/interface2
 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()