def test_Requests(self, data): WriteReport().Creat_Report() params = Parameter().Package_params(data["params"], signature=self.signature) url = Environment().Test() + data["api"] try: # 请求 result = requests.request(data["method"], url, params=params, headers=self.headers) Logging().Info("< Request:" + url + " >< Parameters:" + str(params) + " >< Respose: " + str(result.json())) # 获取报告行数 n = WriteReport().Get_MaxRow() assert int(result.json() ["code"]) == data["code"], WriteReport().Write_Report( n + 1, data["name"], data["api"], data["params"], data["code"], str(result.json())) except Exception as error: error_info = "<AssertionError> " + str( result.json()["code"]) + "≠" + str( data["code"]) + " <Response:" + str(result.json()) + ">" Logging().Error(error_info) raise error
def test_Requests(self, filename): api_list = Read_Data(filename).Get_API() params_list = Read_Data(filename).Get_Params() code_list = Read_Data(filename).Get_Code() name_list = Read_Data(filename).Get_name() for item in range(0, len(api_list)): n = 2 try: params = Parameter().Package_params(params_list[item], signature=self.signature) url = Environment().Test() + api_list[item] result = requests.post(url, params, headers=self.headers) Logging().Info("Request:" + url + " Parameters:" + str(params)) assert int( result.json() ["code"]) == code_list[item], WriteReport().Write_Report( n + 1, name_list[item], api_list[item], params_list[item], code_list[item], str(result.json())) except Exception as error: error_info = "<AssertionError> " + str( result.json()["code"]) + "≠" + str( code_list[item]) + " <Response:" + str( result.json()) + ">" Logging().Error(error_info) raise error
def test_requests(self, data): WriteReport().Creat_Report() url = Environment().PreOnline() + data["api"] time.sleep(0.5) # 请求 result = requests.request(data["method"], url, json=eval(data["params"]), headers=self.headers) Logging().Info("<请求:\t" + url + ">\t<参数:" + data["params"] + ">\t<结果:" + result.text) # 当前时间 now = time.strftime('%Y-%m-%d %H:%M') # 获取报告行数 ReportRow = WriteReport().Get_MaxRow() if int(data["checkType"]) == int(1): Verify(data, result, ReportRow).VerifyValue() elif int(data["checkType"]) == int(2): Verify(data, result, ReportRow).Verifydata() elif int(data["checkType"]) == int(3): Verify(data, result, ReportRow).VerifydataExist() else: Verify(data, result, ReportRow).VerifyCode()
def test_Search_Meeting_Normal(self): params_dict = {"searchKey": "joke", "pageNo": 1, "pageSize": 20} params = Parameter().Package_params(str(params_dict), self.token, self.signature) url = Environment().Test() + self.api try: result = requests.post(url, params, headers=self.headers) Logging().Info("Request:" + url + " Parameters:" + str(params)) self.assertEqual(result.json()["code"], str(1), "断言错误,状态码错啦!!") except Exception as error: error_info = "<AssertionError> " + str( result.json()["code"]) + "≠ 1, Response:" + str(result.json()) Logging().Error(error_info) raise error
def test_Search_Meeting_NoContent(): api = "/meeting/search" signature = HuShi.Config.params_config.signature params_dict = {"searchKey": "", "pageNo": 1, "pageSize": 20} headers = HuShi.Config.params_config.headers params = Parameter().Package_params(str(params_dict), signature=signature) url = Environment().Test() + api try: result = requests.post(url, params, headers=headers) assert result.json()["code"] == "2000021" except Exception as error: info = "AssertionError - " + str(result.json()) + "==> 2000021" Logging().Error(info) raise error
def test_requests(self, data): url = Environment().Test() + data["api"] time.sleep(0.5) # 请求 result = requests.request(data["method"], url, json=eval(data["params"]), headers=self.headers) try: if result.json()["message"] == "系统异常": SendWX().System_error(data["api"]) elif result.json()["status"] == str(500): SendWX().No_service(data["api"]) else: pass except: pass
def test_requests(self, data): WriteReport().Creat_Report() url = Environment().Test() + data["api"] time.sleep(0.5) # 请求 result = requests.request(data["method"], url, json=eval(data["params"]), headers=self.headers) Logging().Info("<请求:\t" + url + ">\t<参数:" + data["params"] + ">\t<结果:" + result.text) # 当前时间 now = time.strftime('%Y-%m-%d %H:%M') # 获取报告行数 n = WriteReport().Get_MaxRow() # 判断是否需要SQL校验 if int(data["is_check"]) == int(1): # 链接数据库,查询比对数据 SQL_check_data = Conn_MySQL().Connect(data["SQL_check"]) try: assert str(data["check_data"]) == str(SQL_check_data["result"]) except: WriteReport().Write_Report(n + 1, data["name"], data["api"], data["params"], str(SQL_check_data), result.text) # Jira提交BUG # KeyIssue().Commit(data["api"],data["params"],result.text,str(check_data),1,sql=data["check"]) error_info = "【断言错误】\t<验证值:" + str( SQL_check_data) + "\t<Response:\t" + result.text + ">" Logging().Error(error_info) raise elif int(data["is_check"]) == int(2): # 链接数据库,查询比对数据 SQL_check_data = Conn_MySQL().Connect(data["SQL_check"]) try: assert str(SQL_check_data["result"]) == str( result.json()["result"][data["check_data"]]) except: WriteReport().Write_Report(n + 1, data["name"], data["api"], data["params"], str(SQL_check_data), result.text) # Jira提交BUG # KeyIssue().Commit(data["api"],data["params"],result.text,str(check_data),1,sql=data["check"]) error_info = "【断言错误】\t<验证值:" + str( SQL_check_data) + "\t<Response:\t" + result.text + ">" Logging().Error(error_info) raise elif int(data["is_check"]) == int(3): # 链接数据库,查询比对数据 SQL_check_data = Conn_MySQL().Connect(data["SQL_check"]) try: # 传值当前时间,用于比对 data["check_data"] = now assert str(data["check_data"]) == str(SQL_check_data["result"]) except: WriteReport().Write_Report(n + 1, data["name"], data["api"], data["params"], str(SQL_check_data), result.text) # Jira提交BUG # KeyIssue().Commit(data["api"],data["params"],result.text,str(check_data),1,sql=data["check"]) error_info = "【断言错误】\t<验证值:" + str( SQL_check_data) + "\t<Response:\t" + result.text + ">" Logging().Error(error_info) raise else: try: assert result.json()["code"] == str(data["code"]) except: # 断言错误报告 WriteReport().Write_Report(n + 1, data["name"], data["api"], data["params"], data["code"], result.text) # Jira提交BUG # KeyIssue().Commit(data["api"], data["params"], result.text, data["code"], 0) error_info = "【断言错误】\t<正确状态码:" + str( data["code"]) + "\t<Response:\t" + result.text + ">" Logging().Error(error_info) raise