def test_login_02(self, action): """ 用例描述:密码错误数据 """ # 写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已经开始执行') conf = Config() data = Login() request = Request.Request(action) #获取域名 host = conf.host_debug req_url = 'http://' + host #获取请求参数 urls = data.url params = data.data header = data.header requestsql = data.selectsql env = conf.environment responsecode = data.responsecode responsesql = data.responsesql casedescription = data.casedec #请求参数化 with allure.step("获取输入参数值,{0}".format(requestsql[1])): try: sqlresult = SqlResult(requestsql[1], env).get_sqlresult() params[1][0]['auth'] = sqlresult['register_name'] except: log.info("执行sql报错::" + requestsql[1]) print(params[1][0]) # 请求接口 api_url = req_url + urls[1] with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header[0], params[0][0])): response = request.post_request(api_url, json.dumps(params[1][0]), header[1]) print(response) assertbody = Assertions() assertbody.assert_text(str(response['code']), str(responsecode[1])) with allure.step( "增加断言,ResponseCode:{0}=TestCode:{1},ResponseHeader:{2}".format( response['code'], responsecode[1], response['header'])): if (response['code'] == responsecode[1]): #assertbody.assert_body(response['body'], 'message','密码错误') assertbody.assert_body(response['header'], 'X-Api-Error-Code', 'ERR_LOGIN_FAILED') else: log.info("执行完成,Code不一致")
def test_updatehierarchy_03(self): """ 用例描述:不变层级,名称重复 """ # 写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已开始执行') conf = Config() data = UpdateHierarchy() # 获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url[2] header = data.header[2] param = data.data[2] responsecode = data.responsecode[2] sql_name = data.sqlname[2] env = conf.environment selectsql = data.selectsql[2] errorcode = data.errorcode[2] parentid = SqlResult(selectsql, env).get_sqlresult() sqlname = str(sql_name).replace('@sqlresult', str(parentid['parent_id'])) pname = SqlResult(sqlname, env).get_sqlresult() # 参数化请求参数 with allure.step("获取输入参数值"): try: param[0]['id'] = parentid['id'] param[0]['name'] = pname['name'] param[0]['parent_id'] = parentid['parent_id'] except: log.info("获取参数失败:{0}".format(param[0])) # 请求接口 api_url = req_url + urls print(api_url) print(param[0]) # post请求 request = Request.Request() with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(api_url, header, param[0])): response = request.post_request(api_url, json.dumps(param[0]), header) print(response) # 增加断言 with allure.step("接口返回结果:{0}".format(response)): if response['code'] == responsecode: assertbody = Assertions() assertbody.assert_text(response['body'], errorcode)
def test_enablehierarchy_02(self): """ 用例描述:正常停用多个组织 """ # 写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已开始执行') conf = Config() data = EnableHierarchy() # 获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url[1] header = data.header[1] param = data.data[1] selectsql = data.selectsql[1] responsecode = data.responsecode[1] env = conf.environment ids = SqlResult(selectsql, env).get_sqlresult_list() myid = [] for i in range(len(ids)): for k, v in ids[i].items(): myid.append(ids[i][k]) print(myid) # 参数化请求参数 with allure.step("获取输入参数值"): try: param[0]['ids'].extend(myid) except: log.info("获取参数失败:{0}".format(param[0])) # 请求接口 api_url = req_url + urls # post请求 request = Request.Request() with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header, param[0])): response = request.post_request(api_url, json.dumps(param[0]), header) print(response) # 增加断言 with allure.step("接口返回结果:{0}".format(response)): if response['code'] == responsecode: assertbody = Assertions() assertbody.assert_text(response['body'], True)
def test_deletehierarchy_01(self): """ 用例描述:正常删除一个层级 """ #写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已开始执行') conf = Config() data = DeleteHierarchy() #获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url[0] header = data.header[0] param = data.data[0] my_param = param[0]['id'] selectsql = data.selectsql[0] responsecode = data.responsecode[0] env = conf.environment ids = SqlResult(selectsql, env).get_sqlresult() # 参数化请求参数 with allure.step("获取输入参数值"): try: param[0]['id'].append(ids['id']) except: log.info("获取参数失败:{0}".format(param[0])) #请求接口 api_url = req_url + urls print(api_url) #post请求 request = Request.Request() with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header, param[0])): response = request.post_request(api_url, json.dumps(my_param), header) print(response) # 增加断言 with allure.step("接口返回结果:{0}".format(response)): if response['code'] == responsecode: assertbody = Assertions() assertbody.assert_text(response['body'], True)
def test_hierarchy_01(self): """ 用例描述:获取目录 """ #写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已开始执行') conf = Config() data = GetHierarchy() #获取请求域名 host = conf.host_debug req_url = 'http://' + host env = conf.environment responsesql = data.responsesql responsecode = data.responsecode # 获取请求参数 urls = data.url header = data.header #请求接口 api_url = req_url + urls request = Request.Request() with allure.step("开始请求接口,RUL: {0},header:{1}".format(api_url, header)): response = request.get_request(api_url, None, header) print(response['body']) # 数据库查询结果 try: # print(responsesql) responsesqlresult = SqlResult(responsesql, env).get_sqlresult_list() print(responsesqlresult) with allure.step("获取预期结果值成功"): log.info('查询结果数据库成功:' + responsesql) except: log.info('查询结果数据库失败:' + responsesql) print(responsecode) # 增加断言 assertbody = Assertions() with allure.step("增加断言,接口返回结果:{0}".format(response)): assertbody.assert_text(str(response['code']), str(responsecode)) if response['code'] == responsecode: for i in range(len(responsesqlresult)): for k, v in responsesqlresult[i].items(): assertbody.assert_body(response['body'][i], k, responsesqlresult[i][k])
def test_0002_a_precisefind(self): """ 根据被保险人查询单子 :return: """ Con = Config() test = Assertions() allure = Allure() reques = Request.Request(self.evn) data = Basic() urls = data.url parms = data.data headers = data.header json_header = {'Authorization': 'bearer%s' % reques.get_session} host = Con.host_debug req_url = 'https://' + host test_data=Con.get_conf(Con.TITLE_DATA, Config.VALUE_insuredPerson) api_url = req_url + urls[0]['url_2']+ test_data response = reques.get_request(api_url,json_header) allure.allure_step('第一步','查询单子','根据被保险人,精准查询单子数量:%s'%response['jsons']['total']) print('根据被保险人,精准查询单子数量:%s'%response['jsons']['total']) assert test.assert_text(response['jsons']['total']>1,True)
def test_addhierarchy_07(self): """ 用例描述:name字段传空 """ # 写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已经开始执行') conf = Config() data = AddHierarchy() # 获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url[4] header = data.header[4] param = data.data[4] env = conf.environment responsecode = data.responsecode[4] responsesql = data.responsesql[4] selectsql = data.selectsql[4] errorcode = data.errorcode[4] print(param[0]) # 请求接口 api_url = req_url + urls print(api_url) # post请求 request = Request.Request() with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header, param[0])): response = request.post_request(api_url, json.dumps(param[0]), header) print(response) # 增加断言 with allure.step("接口返回结果:{0}".format(response)): if response['code'] == responsecode: assert response['body'] assertbody = Assertions() assertbody.assert_text(response['header']['X-Api-Error-Code'], errorcode)
def test_0001_add(self): """创建新单""" Con=Config() test=Assertions() allure=Allure() reques= Request.Request(self.evn) data=Basic() urls=data.url parms=data.data headers=data.header Con.set_item(Con.TITLE_DATA,Con.VALUE_policyNo,self.create_time() + '-' + self.create_unix()) Con.set_item(Con.TITLE_DATA,Con.VALUE_reportNo,self.create_time() + '-' + self.create_unix()) Con.set_item(Con.TITLE_DATA,Con.VALUE_reporttime,self.create_time()) policyNo = Con.get_conf(Con.TITLE_DATA, Config.VALUE_policyNo) reportNo = Con.get_conf(Con.TITLE_DATA, Config.VALUE_reportNo) json_data ={'reportDate':self.create_now_time(), "insuranceComName": Con.insuranceComName, "insuredPerson": Con.insuredPerson, "policyNo":policyNo, "reportNo":reportNo, } data_new =dict(parms[0],**json_data) json_header={'Authorization': 'bearer %s' % reques.get_session} header_new=dict(headers[0],**json_header) host = Con.host_debug req_url ='https://'+ host api_url = req_url + urls[0]['url_1'] response = reques.post_request(api_url,json.dumps(data_new), header_new) allure.allure_step('第一步', '添加单子',(response['stats'])) assert test.assert_code(response['code'], 200) assert test.assert_text((response['stats'])['success'],True) #查询事故号: req_url_1 = 'https://' + host url_find = req_url_1+ urls[0]['url_2']+'&policyNo='+ policyNo+'&reportDate=' res = reques.get_request(url_find,json_header) Con.set_item(Con.TITLE_DATA, Con.VALUE_reporttid,res['jsons']['rows'][0]['id']) allure.allure_step('第二步', '查询单子','事故号id为:%s' %res['jsons']['rows'][0]['id']) print('事故号id为:%s' %res['jsons']['rows'][0]['id'])
def test_addhierarchy_02(self): """ 用例描述:创建三级组织 """ #写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已开始执行') conf = Config() data = AddHierarchy() #获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url[1] header = data.header[1] param = data.data[1] env = conf.environment responsecode = data.responsecode[1] responsesql = data.responsesql[1] selectsql = data.selectsql[1] print(param[0]) parentid = SqlResult(selectsql, env).get_sqlresult() # 参数化请求参数 with allure.step("获取输入参数值"): try: param[0]['name'] = '国联信息' + str(int(time.time())) param[0]['parent_id'] = parentid['id'] except: log.info("获取参数失败:{0}".format(param[0])) #请求接口 api_url = req_url + urls print(api_url) #post请求 request = Request.Request() with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header, param[0])): response = request.post_request(api_url, json.dumps(param[0]), header) print(response) # 数据库查询结果 try: responsesql = str(responsesql).replace('@sqlresult', str(parentid['id'])) responsesqlresult = SqlResult(responsesql, env).get_sqlresult_list() with allure.step("获取预期结果值成功,查询Sql:{0},查询结果:{1}".format( responsesql, responsesqlresult)): log.info('查询结果数据库成功:' + responsesql) except: log.info('查询结果数据库失败:' + responsesql) actual = [] for i in range(len(responsesqlresult)): for k, v in responsesqlresult[i].items(): actual.append(responsesqlresult[i][k]) # 增加断言 assertbody = Assertions() with allure.step("接口返回结果:{0}".format(response)): assertbody.assert_text(str(response['code']), str(responsecode)) if response['code'] == responsecode: assert param[0]['name'] in actual
def test_addhierarchy_09(self): """ 用例描述:同一层级不同上级name重复 """ # 写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已经开始执行') conf = Config() data = AddHierarchy() # 获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url[6] header = data.header[6] param = data.data[6] env = conf.environment responsecode = data.responsecode[6] responsesql = data.responsesql[6] sqlparentid = data.sqlpid[6] sqlname = data.sqlname[6] selectsql = data.selectsql[6] parentid = SqlResult(selectsql, env).get_sqlresult() # 参数化请求参数 with allure.step("获取输入参数值"): try: param[0]['parent_id'] = parentid['id'] param[0]['name'] = '同层级不同上级' + str(int(time.time())) except: log.info("获取参数失败:{0}".format(param[0])) # 请求接口 api_url = req_url + urls print(api_url) print(param[0]) request = Request.Request() addname = request.post_request(api_url, json.dumps(param[0]), header) # dsqlname = str(sqlname).replace('@sqlresult', str(parentid['id'])) sqlid = str(sqlparentid).replace('@sqlresult', str(parentid['id'])) # param[0]['name'] = SqlResult(dsqlname, env).get_sqlresult()['name'] param[0]['parent_id'] = SqlResult(sqlid, env).get_sqlresult()['id'] ############################ print(param[0]) # post请求 with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header, param[0])): response = request.post_request(api_url, json.dumps(param[0]), header) print(response) # 增加断言 with allure.step("接口返回结果:{0}".format(response)): if response['code'] == responsecode: assertbody = Assertions() assertbody.assert_text(response['body'], True)
def test_login_01(self, action): """ 用例描述:测试正常登录 """ # 写log with allure.step("写入Log"): log = Log.MyLog() log.info('文件已经开始执行') conf = Config() data = Login() request = Request.Request(action) #获取域名 host = conf.host_debug req_url = 'http://' + host #获取请求参数 urls = data.url params = data.data header = data.header requestsql = data.selectsql env = conf.environment responsecode = data.responsecode responsesql = data.responsesql casedescription = data.casedec #请求参数化 with allure.step("获取输入参数值,{0}".format(requestsql[1])): try: sqlresult = SqlResult(requestsql[0], env).get_sqlresult() params[0][0]['auth'] = sqlresult['register_name'] except: log.info("执行sql报错::" + requestsql[0]) print(params[0][0]) # 请求接口 api_url = req_url + urls[0] with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format( api_url, header[0], params[0][0])): response = request.post_request(api_url, json.dumps(params[0][0]), header[0]) print(response) # 数据库查询结果 try: responsesql = str(responsesql[0]).replace( '@sqlresult', sqlresult['register_name']) responsesqlresult = SqlResult(responsesql, env).get_sqlresult() with allure.step("获取预期结果值成功,查询Sql:{0},查询结果:{1}".format( responsesql, responsesqlresult)): log.info('查询结果数据库成功:' + responsesql) except: log.info('查询结果数据库失败:' + responsesql) # 增加断言 assertbody = Assertions() # if response['code'] == responsecode[0]: # for k, v in responsesqlresult.items(): # assertbody.assert_body(response['body'], k,responsesqlresult[k]) # if not assertbody.assert_body(response['body'], k, responsesqlresult[k]): # break # allure.attach(k, params[0][0]) with allure.step("接口返回结果:{0}".format(response)): assertbody.assert_text(str(response['code']), str(responsecode[0]))
def test_hierarchy_01(self, action): """ 用例描述:获取目录 """ allure.step("获取目录") # 写log log = Log.MyLog() log.info('文件已经开始执行') conf = Config() data = GetHierarchy() with allure.step("写入Log"): allure.attach('写入log', '文件已经开始执行') request = Request.Request(action) # 获取请求域名 host = conf.host_debug req_url = 'http://' + host # 获取请求参数 urls = data.url #params = data.data header = data.header #requestsql = data.selectsql env = conf.environment responsecode = data.responsecode responsesql = data.responsesql #casedescription = data.casedec #获取token token = Session().get_session('debug') print(token) dict_token = {'X-Api-Authorization': token} header = dict(header) header.update(dict_token) print(header) # 请求接口 api_url = req_url + urls print(api_url) print(header) response = request.get_request(api_url, None, header) with allure.step("开始请求接口"): allure.attach('header', header) allure.attach('response', response) print(response) # 数据库查询结果 try: responsesql = str(responsesql[0]).replace( '@sqlresult', str(response['body']['id'])) responsesqlresult = SqlResult(responsesql, env).get_sqlresult() print(responsesqlresult) with allure.step("获取预期结果值成功"): allure.attach('获取SQL', responsesql) except: with allure.step("获取预期结果值失败"): allure.attach('获取SQL', responsesql) print(responsesqlresult['parent_id']) # 增加断言 assertbody = Assertions() assertbody.assert_text(str(response['code']), str(responsecode[0])) if (response['code'] == responsecode[0]): assertbody.assert_body(response['body'], 'id', responsesqlresult['id']) assertbody.assert_text(responsesqlresult['name'], params[0][0]['name']) assertbody.assert_text(str(responsesqlresult['parent_id']), 'None') allure.step("断言完成") else: with allure.step("执行完成,Code不一致"): allure.attach('request', params[0][0])