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, 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_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 VerifyCode(self): try: assert self.result.json()["code"] == str(self.data["code"]) except: # 断言错误报告 WriteReport().Write_Report(self.ReportRow + 1, self.data["name"], self.data["api"], self.data["params"], self.data["code"], self.result.text) # Jira提交BUG # KeyIssue().Commit(self.data["api"], self.data["params"], self.result.text, self.data["code"], 0) error_info = "【断言错误】\t<正确状态码:" + str( self.data["code"]) + "\t<Response:\t" + self.result.text + ">" Logging().Error(error_info) raise
def Verifydata(self): # 链接数据库,查询比对数据 SQL_check_data = Conn_MySQL().Connect(self.data["SQL_check"]) try: assert str(SQL_check_data["result"]) == str( self.result.json()["result"][self.data["check_data"]]) except: WriteReport().Write_Report(self.ReportRow + 1, self.data["name"], self.data["api"], self.data["params"], str(SQL_check_data), self.result.text) # Jira提交BUG # KeyIssue().Commit(self.data["api"],self.data["params"],self.result.text,str(check_self.data),1,sql=self.data["check"]) error_info = "【断言错误】\t<验证值:" + str( SQL_check_data) + "\t<Response:\t" + self.result.text + ">" Logging().Error(error_info) raise
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