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)
class TestBasic(object): log = Log.MyLog() data = Basic() case_data = data.case_data request = Request.Request() test = Assert.Assertions() config = Config() noti = notify() # ids = [ # "测试:{}". # format(case['test_name']) for case in case_data # ] @allure.feature('Home') @allure.severity('blocker') @allure.story('Basic') @allure.issue('https://baidu.com') @allure.testcase('https://baidu.com') @pytest.mark.flaky(reruns=3) # @pytest.mark.parametrize('case', case_data, ids=ids) @pytest.mark.parametrize('case', case_data) def test_login(self,case): """ 小程序登录 """ self.log.info('demo, utl={}, data={}, header={}'.format(case['url'], case['data'], case['header'])) if case['method'] == 'post_request_urlencoded': result = self.request.post_request_urlencoded(case['url'], case['data'], case['header']) # 写入配置文件 self.config.set_conf('parameter', 'token', result['data']['token']) assert self.test.assert_text(result['status'], 0) self.log.info('配置文件中token ={}'.format(self.config.get_conf('parameter', 'token'))) allure.attach.file(BASE_PATH+'/Log/log.log', '附件内容是: ' + '老王调试日志', '我是附件名', allure.attachment_type.TEXT) Consts.RESULT_LIST.append('True')
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_basic_02(self, action): """ 用例描述:登陆状态下查看基础设置 """ conf = Config() data = Basic() test = Assert.Assertions() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[1] response = request.post_request(api_url, params[1], headers[1]) assert test.assert_code(response['code'], 401) assert test.assert_text(response['text'], '{"error":"继续操作前请注册或者登录."}') Consts.RESULT_LIST.append('True')
def get_session(self, env): """ 获取session :param env: 环境变量 :return: """ data = Basic() urls = data.url headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded" } if env == "debug": login_url = 'http://' + self.config.loginHost_debug parm = eval(self.config.loginInfo_debug) session_debug = requests.session() response = session_debug.post(login_url, parm, headers=headers) # print(json.loads(response.text)['access_token']) self.config.set_item(self.config.TITLE_DEBUG, self.config.VALUE_TOkEN, json.loads(response.text)['access_token']) # self.log.debug('cookies: %s' % response.cookies.get_dict()) return json.loads(response.text)['access_token'] elif env == "release": login_url = 'http://' + self.config.loginHost_release parm = self.config.loginInfo_release session_release = requests.session() response = session_release.post(login_url, parm, headers=headers) self.config.set_item(self.config.TITLE_DEBUG, self.config.VALUE_TOkEN, json.loads(response.text)['access_token']) # self.log.debug('cookies: %s' % response.cookies.get_dict()) return json.loads(response.text)['access_token'] else: print("get cookies error")
def test_basic_01(self, action): """ 用例描述:未登陆状态下查看基础设置 """ conf = Config() data = Basic() test = Assert.Assertions() request = Request.Request(action) host = conf.host_debug req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[0] response = request.get_request(api_url, params[0], headers[0]) assert test.assert_code(response['code'], 401) assert test.assert_body(response['body'], 'error', u'继续操作前请注册或者登录.') assert test.assert_time(response['time_consuming'], 100) Consts.RESULT_LIST.append('True')
def test_basic_01(self, action): """ 用例描述:未登陆状态下查看基础设置 """ conf = Config() data = Basic() test = Assert.Assertions() request = Request.Request(action) req_url = conf.host_debug urls = data.url # params = data.data headers = data.header api_url = req_url + urls[0] response = request.get_request(api_url, None, headers[0]) assert test.assert_code(response['code'], 200) assert test.assert_body(response['body'], 'code', 1) assert test.assert_body(response['body'], 'message', '操作成功') assert test.assert_time(response['time_consuming'], 500) Consts.RESULT_LIST.append('True')
def test_user_login(self): """ 用例描述:登陆 """ conf = Config() data = Basic() test = Assert.Assertions() host = conf.host_test req_url = 'http://' + host urls = data.url params = data.data headers = data.header api_url = req_url + urls[0] response = requests.post(api_url, data=json.dumps(params[0]), headers=headers[0]) r_data = response.json() # 断言 allure.attach("实际结果", "{}".format(r_data)) assert test.assert_code(response.status_code, 200) Consts.RESULT_LIST.append('True')
def test_0003_a_saveFirstTrackPojo(self): """ 诊疗类型:无治疗--暂存 :return: """ Con = Config() test = Assertions() allure = Allure() reques = Request.Request(self.evn) data = Basic() urls = data.url parms = data.data headers = data.header #不用初始化 id = Con.get_conf(Con.TITLE_DATA, Config.VALUE_injureCaseId) # 获取id policyNo = Con.get_conf(Con.TITLE_DATA, Config.VALUE_policyNo) # 获取保单号 reportNo = Con.get_conf(Con.TITLE_DATA, Config.VALUE_reportNo) # 获取事故号 #初始化 # diagnoseType=Con.get_conf(Con.TITLE_DATA,Config.VALUE_diagnoseType)#人伤类型 # licensePlate = Con.get_conf(Con.TITLE_DATA, Config.VALUE_licensePlate) # 获取车牌 # accidentdutytype = Con.get_conf(Con.TITLE_DATA, Config.VALUE_accidentDutyType) # 事故责任类型 Con.set_item(Con.TITLE_DATA,Config.VALUE_time,self.create_now_time())#获取时间 createDate =Con.get_conf(Con.TITLE_DATA,Config.VALUE_time)#创建时间 injuredName =Con.get_conf(Con.TITLE_DATA,Config.VALUE_injuredName)#人伤姓名 injuredCertificateNum = Con.get_conf(Con.TITLE_DATA, Config.VALUE_injuredCertificateNum) # 身份证 injuredCertificateType =Con.get_conf(Con.TITLE_DATA,Config.VALUE_injuredCertificateType)#证件类型 injuredPhone =Con.get_conf(Con.TITLE_DATA,Config.VALUE_injuredPhone)#联系号码 livingStatus =Con.get_conf(Con.TITLE_DATA,Config.VALUE_livingStatus)#生存状态 # injuredBirthday =Con.get_conf(Con.TITLE_DATA,Config.VALUE_injuredBirthday)#伤者出生日期 # injuredAge =Con.get_conf(Con.TITLE_DATA,Config.VALUE_injuredAge)#伤者年龄 detailAddress =Con.get_conf(Con.TITLE_DATA,Config.VALUE_detailAddress)#常住地址 injuredSex =Con.get_conf(Con.TITLE_DATA,Config.VALUE_injuredSex)#常住地址 #赔偿标准信息 compensateBasis =Con.get_conf(Con.TITLE_DATA,Config.VALUE_compensateBasis)#赔偿依据 compensateYear =Con.get_conf(Con.TITLE_DATA,Config.VALUE_compensateYear)#赔偿年度 industry =Con.get_conf(Con.TITLE_DATA,Config.VALUE_industry)#从事行业 #案件处理信息 trackRecord=Con.get_conf(Con.TITLE_DATA,Config.VALUE_trackRecord)#案件处理信息 taskType = '01' # 01-首次跟踪,02-后续跟踪,03-跟踪审核 taskState = '1' # 0-未开始,1-处理中,2-已完成 #important info 单号重点 check_json_value(parms[1], 'id', id) # id check_json_value(parms[1], "policyNo", policyNo) # 保单号 check_json_value(parms[1], 'reportNo', reportNo, ) # 事故号 #base info 基本信息 check_json_value(parms[1], 'diagnoseType', Con.diagnoseType)#人伤类型0一般损伤,1残疾,2死亡 check_json_value(parms[1], 'injureCaseId',id)#id check_json_value(parms[1], 'reportDate',self.create_now_time())#创建时间 check_json_value(parms[1], 'createDate',self.create_now_time())#流入时间 check_json_value(parms[1], "licensePlate","粤A12345")#c车牌号 check_json_value(parms[1], "accidentDutyType",Con.accidentDutyType)#车牌号 #user info 用户信息 check_json_value(parms[1], "injuredName",injuredName)#伤亡人员 check_json_value(parms[1], "injuredCertificateType",injuredCertificateType)#证件类型 check_json_value(parms[1], "injuredCertificateNum",injuredCertificateNum)#身份证号码 check_json_value(parms[1], "injuredPhone",injuredPhone,)#身份证电话 check_json_value(parms[1], "livingStatus",livingStatus,)#生存状态 res = count_data(injuredCertificateNum) check_json_value(parms[1], "injuredBirthday", res['data']) # 伤者出生日期 check_json_value(parms[1], "injuredAge", res['age']) # 伤者年龄 check_json_value(parms[1], "injuredSex", injuredSex) # 伤者性别 check_json_value(parms[1], "accidentSite","福建省-泉州市")#事故地 check_json_value(parms[1], "accidentSiteId","350500")#事故地 check_json_value(parms[1], "domicilePlace","福建省-泉州市")#户籍所在地 check_json_value(parms[1], "domicilePlaceId","360100")#户籍所在地 check_json_value(parms[1], "habitualResidence","江西省-南昌市")#经常居住地 check_json_value(parms[1], "habitualResidenceId","360100")#经常居住地 check_json_value(parms[1], "detailAddress",detailAddress)#常住地址 #赔偿标准信息 check_json_value(parms[1], "compensateBasis", compensateBasis) # 赔偿标准 check_json_value(parms[1], "compensateYear", compensateYear) # 赔偿年度 check_json_value(parms[1], "industry", industry) # 赔偿年度 #案件处理信息 check_json_value(parms[1], "trackRecord", trackRecord) # 赔偿年度 #重点在这 check_json_value(parms[1]['hidTrackInjureDiagnose'][0], 'injureCaseId', id) check_json_value(parms[1]['hidTrackCompensateFee'][0], 'injureCaseId', id) check_json_value(parms[1]['hidTrackCompensateFee'][0]['hidTrackCompensateDetail'][0], 'injureCaseId', id) json_header = {'Authorization': 'bearer%s' % reques.get_session} header_new = dict(headers[1], **json_header) # print(parms[1]['hidTrackInjureDiagnose']) print(parms[1]) host = Con.host_debug req_url = 'https://' + host api_url = req_url + urls[1] response = reques.post_request(api_url,json.dumps(parms[1]), header_new) print(response['jsons']) # assert test.assert_in_text(response['jsons']['success'],True) print(parms[1])
def __init__(self): self.url_all = 'https://nicefoodtest.com' self.order_sn = None self.total_amount = None self.data = Basic()