class API_DL_ABNL(unittest.TestCase): ddt_tools=ExcelDDTTools() data_list=ddt_tools.get_ddt_datalist('DL') @classmethod def setUpClass(self): self.exceltest = ExcelDDTTools() self.db = DataBaseTools() self.log = LogTools() self.log.info('>>>>>>>>>>>>>>>>>>>>>[DL_api_abnl_start]<<<<<<<<<<<<<<<<<<<<') @classmethod def tearDownClass(self): self.db.cur_close() # 关闭游标 self.log.info('>>>>>>>>>>>>>>>>>>>>>[DL_api_abnl_end]<<<<<<<<<<<<<<<<<<<<<<') @data(*data_list) def test_dl_abnl(self,data): '''用户登录类-api接口异常情况测试''' self.exceltest.send_request(data)
class API_TC(unittest.TestCase): '''退出注销类api接口测试''' def setUp(self): self.log = LogTools() self.yaml = YamlTools() self.req = RequestTools() self.db = DataBaseTools() self.api = CommonApiTools() self.log.info( '>>>>>>>>>>>>>>>>>>>>>[TC_api_start]<<<<<<<<<<<<<<<<<<<<') def tearDown(self): self.db.cur_close() #关闭游标 self.log.info( '>>>>>>>>>>>>>>>>>>>>>[TC_api_end]<<<<<<<<<<<<<<<<<<<<<<') def test_1_logout(self): '''退出注销类-退出注销''' casename = '退出注销' api = self.yaml.get_TCapi(0) #获取数据 sql1 = 'select * from userlogin;' userid = self.db.get_specific_data(sql1, 0, 3) # 发送请求 try: self.api.login_api_pwd() #先登录 data = 'userid=%s' % userid result = self.req.post_method('urlencode', api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) and self.assertEqual( result['errorMessage'], '退出登录成功!') self.log.info('[%s]-[Result]:PASS' % casename) #更新登陆状态 sql2 = 'update userlogin set dlbz=0 where userid=\'%s\';' % userid self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) raise
class API_ZC_ABNL(unittest.TestCase): '''用户注册类api接口异常测试''' #获取测试用例数据 ddt_tools = ExcelDDTTools() data_list = ddt_tools.get_ddt_datalist('ZC') @classmethod def setUpClass(self): self.exceltest = ExcelDDTTools() self.db = DataBaseTools() self.log = LogTools() self.log.info( '>>>>>>>>>>>>>>>>>>>>>[ZC_api_abnl_start]<<<<<<<<<<<<<<<<<<<<') @classmethod def tearDownClass(self): self.db.cur_close() # 关闭游标 self.log.info( '>>>>>>>>>>>>>>>>>>>>>[ZC_api_abnl_end]<<<<<<<<<<<<<<<<<<<<<<') @data(*data_list) # 数据驱动 def test_zc_abnl(self, data): '''用户注册类-api接口异常用例''' self.exceltest.send_request(data)
class API_ZC(unittest.TestCase): '''注册类api接口测试''' @classmethod def setUpClass(self): self.log = LogTools() self.yaml = YamlTools() self.req = RequestTools() self.db = DataBaseTools() self.log.info( '>>>>>>>>>>>>>>>>>>>>>[ZC_api_start]<<<<<<<<<<<<<<<<<<<<') @classmethod def tearDownClass(self): self.db.cur_close() #关闭游标 self.log.info( '>>>>>>>>>>>>>>>>>>>>>[ZC_api_end]<<<<<<<<<<<<<<<<<<<<<<') def test_001_getfzcid(self): '''获取非注册用户标识id''' casename = '获取非注册用户标识id' sql1 = 'select * from userregister;' phoneid = self.db.get_specific_data(sql1, 0, 6) #从数据库中获取手机号码数据 api = self.yaml.get_ZCapi(0) data = {'phoneid': phoneid} # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) #更新数据库fzcuid字段 sql2 = 'update userregister set fzcuid=\'%s\' where phoneid=\'%s\'' % ( result['result'], phoneid) self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_002_getverifycode(self): '''获取验证码''' casename = '获取验证码' api = self.yaml.get_ZCapi(2) sql1 = 'select * from verifycode;' telnum = self.db.get_specific_data(sql1, 0, 0) #从数据库中获取手机号数据 data = {'mobile': telnum, 'isregister': 1} # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) #更新数据库verifycode字段 sql2 = 'update verifycode set verifycode=\'%s\' where telnum=\'%s\'' % ( result['result'], telnum) self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_003_register(self): '''正式注册''' casename = '正式注册' api = self.yaml.get_ZCapi(1) sql1 = 'select * from userregister;' sql2 = 'select * from verifycode;' #获取数据信息--tuple sql1data = self.db.get_selectdata_row(sql1, 0) sql2data = self.db.get_selectdata_row(sql2, 0) #获取数据库数据信息 username = sql1data[1] password = sql1data[3] fzcuid = sql1data[4] telnum = sql2data[0] verifycode = sql2data[1] data = { "userid": fzcuid, "username": username, "mobile": telnum, "password": password, "validcode": verifycode } # 发送请求 try: result = self.req.post_method('json', api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) #更新数据库内容--注册领驭号 sql3 = 'update userregister set zcuid=\'%s\' where telnum=\'%s\';' % ( result['result'], telnum) sql4 = 'update userlogin set zcuid=\'%s\' where telnum=\'%s\';' % ( result['result'], telnum) #更新用户注册状态 sql5 = 'update userregister set zcbz=1 where telnum=\'%s\';' % telnum self.db.execute_sql(sql3) self.db.execute_sql(sql4) self.db.execute_sql(sql5) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) raise
class API_DL(unittest.TestCase): '''登录类api接口测试''' def setUp(self): self.log = LogTools() self.yaml = YamlTools() self.req = RequestTools() self.db = DataBaseTools() self.api = CommonApiTools() def tearDown(self): self.db.cur_close() # 关闭游标 self.api.logout_api() # 退出登陆 def test_001_loginbypassword_uid(self): '''用户登录类-密码方式登陆认证(通过uid以及password进行登陆)''' self.log.info( '>>>>>>>>>>>>>>>>>>>>>[DL_api_start]<<<<<<<<<<<<<<<<<<<<') casename = '密码方式登陆认证_uid认证' api = self.yaml.get_DLapi(0) sql1 = 'select * from userlogin;' sql1data = self.db.get_selectdata_row(sql1, 0) #获取数据库数据 zcuid = sql1data[2] password = sql1data[1] phoneid = sql1data[4] data = {'userid': zcuid, 'pwd': password, 'phoneid': phoneid} # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) #更新数据库信息--用户领驭号、token sql2='update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';'\ %(result['result']['userid'],result['result']['token'],phoneid) self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_002_loginbypassword_mobile(self): '''用户登录类-密码方式登陆认证(通过mobile以及password进行登陆)''' casename = '密码方式登陆认证_mobile认证' api = self.yaml.get_DLapi(0) sql1 = 'select * from userlogin;' sql1data = self.db.get_selectdata_row(sql1, 0) #获取数据库数据 mobile = sql1data[0] password = sql1data[1] phoneid = sql1data[4] data = {'mobile': mobile, 'pwd': password, 'phoneid': phoneid} # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) #更新数据库信息--用户领驭号、token sql2 = 'update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';' \ % (result['result']['userid'], result['result']['token'], phoneid) self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_003_loginbypassword_uid_mobile(self): '''用户登录类-密码方式登陆认证(通过uid、mobile以及password进行登陆)''' casename = '密码方式登陆认证_uid/mobile认证' api = self.yaml.get_DLapi(0) sql1 = 'select * from userlogin;' sql1data = self.db.get_selectdata_row(sql1, 0) #获取数据库数据 zcuid = sql1data[2] mobile = sql1data[0] password = sql1data[1] phoneid = sql1data[4] data = { 'userid': zcuid, 'mobile': mobile, 'pwd': password, 'phoneid': phoneid } # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) #更新数据库信息--用户领驭号、token sql2 = 'update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';' \ % (result['result']['userid'], result['result']['token'], phoneid) self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_004_loginbyverifycode(self): '''用户登录类-验证码方式登陆认证''' casename = '验证码方式登陆认证' api = self.yaml.get_DLapi(1) #获取登陆验证码 self.api.get_verifycode(0) #获取数据库数据 sql1 = 'select * from userlogin;' sql1data = self.db.get_selectdata_row(sql1, 0) telnum = sql1data[0] loginverifycode = sql1data[7] phoneid = sql1data[4] data = { 'mobile': telnum, 'validcode': loginverifycode, 'phoneid': phoneid } # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) # 更新数据库信息--用户领驭号、token、登陆标志 sql2 = 'update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';' \ % (result['result']['userid'], result['result']['token'], phoneid) self.db.execute_sql(sql2) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_005_checkmobile(self): '''用户登录类-检查手机号码是否注册(手机号码已经注册)''' casename = '检查手机号码是否注册-已经注册' sql = 'select * from userlogin;' #获取数据 telnum = self.db.get_specific_data(sql, 0, 0) api = self.yaml.get_DLapi(2) data = {'mobile': telnum} # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 0) and self.assertEqual( result['isTrue'], True) and self.assertEqual( result['errorMessage'], '该手机号码已经注册!') self.log.info('[%s]-[Result]:PASS' % casename) self.log.info('-' * 60) except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info('-' * 60) raise def test_006_checkmoblie(self): '''用户登录类-检查手机号码是否注册(手机号码未注册)''' casename = '检查手机号码是否注册-未注册' sql = 'select * from userlogin;' #获取数据 telnum = self.db.get_specific_data(sql, 1, 0) api = self.yaml.get_DLapi(2) data = {'mobile': telnum} # 发送请求 try: result = self.req.get_method(api, casename, data) self.assertEqual(result['errorCode'], 10351) and self.assertEqual( result['isTrue'], False) and self.assertEqual( result['errorMessage'], '该手机未注册') self.log.info('[%s]-[Result]:PASS' % casename) self.log.info( '>>>>>>>>>>>>>>>>>>>>>[DL_api_end]<<<<<<<<<<<<<<<<<<<<<<') except Exception: self.log.error('[%s]-[Result]:FAILED' % casename) self.log.info( '>>>>>>>>>>>>>>>>>>>>>[DL_api_end]<<<<<<<<<<<<<<<<<<<<<<') raise