def test_risk_api(self, item): '''''' res = HttpRequests().http_requests(item["Method"], item["Url"], json=eval(item["Params"]), header=eval(item["Headers"])) self.result = res.json() # 响应结果以 json 形式解释 # respone_result = json.loads(self.result) # 将响应结果由 json 转化为 dict test_result = None # 定义测试结果为 None self.respone_time = res.elapsed.total_seconds() # 记录接口响应时间 logging.info( "正在进行{0}接口请求,执行第{1}条用例,请求的内容是{2},请求url是{3},请求header是{4},请求参数是{5}". format(item["Module"], item["Id"], item["Description"], item["Url"], item["Headers"], item["Params"])) try: self.assertTrue(AssertDict().is_contain( eval(item["ExpectedResult"]), self.result), True) # 断言是否为真 test_result = 'PASS' except Exception as e: logging.error("请求出错,结果为{0},请求参数为{1}".format( e, eval(item["Params"]))) test_result = "FAULT" finally: DoeExcel().write_back(file_name, item["sheet_name"], item["Id"], str(self.result), test_result) logging.info("已执行写回 excel 操作")
def get_urls(): url_list = [] host = "https://book.douban.com/" url = r"tag/编程?start=20&type=T" http = HttpRequests(host) result = http.get(url, headers=http.headers) html = result[1] soup = bs(html, "html.parser") # 定义一个BeautifulSoup变量 items = soup.find_all('a', attrs={'class': 'nbg'}) for i in items: idl = i.get('href') # id_img = i.img.get('src') url_list.append(idl) return url_list
def setUpClass(cls) -> None: cls.url = Conf.TEST_URL.value cls.http = HttpRequests(cls.url) cls.mysql = Mysql_connet('device') cls.mysql.insert_device() cls.device_id = cls.mysql.select_sql( 'select id from t_cellar_well where id={}'.format(cls.mysql.device_id))
def setUpClass(cls) -> None: cls.url = Conf.TEST_APP_URL.value cls.http = HttpRequests(cls.url) cls.mysql = Mysql_connet('device') cls.mysql.insert_user()
def setUpClass(cls) -> None: cls.url = Conf.TEST_URL.value cls.http = HttpRequests(cls.url)
def setUpClass(cls) -> None: cls.url = Conf.TEST_URL.value cls.http = HttpRequests(cls.url) cls.mysql = Mysql_connet('base')
def setUpClass(cls) -> None: cls.host = 'https://route.showapi.com/' cls.http = HttpRequests(cls.host) cls.showapi_appid = "467516" cls.showapi_sign = "5cd5bb087f864a08b16a3ecb27cf4172"
def setUpClass(cls) -> None: cls.url = Conf.TEST_URL.value cls.http = HttpRequests(cls.url) cls.mysql = Mysql_connet('user') cls.mysql.delete_user() cls.mysql.insert_user()