def testQueryState_ok(self): CommomUtils.Connect() HR = HttpRequest.HttpRequest() data = HR.open("camera._queryState") self.assertIsNotNone(data['state'], '获取state失败!') self.assertTrue(data['state'] == 'done', 'state不等于done!') self.assertTrue(data.has_key('results'), '没有results关键字!') results = data['results'] self.assertIsNotNone(results, '获取results失败!') preview = results['preview'] self.assertIsNotNone(preview['width'], '获取width失败!') self.assertIsNotNone(preview['url'], 'preview获取失败!') self.assertIsNotNone(results['version'], '获取version失败')
def testGetStoragePath_ok(self): CommomUtils.Connect() HR = HttpRequest.HttpRequest() param = StartPreviewParam.StartPreview(stimime='h264', stiframe='30', stiwidth='1920', stibitrate='1000', stiheight='960', stimode='pano', orimime='h265', oriframe='30', oriwidth='1920', oribitrate='15000', oriheight='1440', saveori='false').getJsonData() preivewdata = HR.open('camera._startPreview', parameters=param) print(preivewdata) data = HR.open("camera._getStoragePath") print(data) self.assertIsNotNone(data['state'], '获取state失败!') self.assertTrue(data['state'] == 'done', 'state不等于done!') self.assertTrue(data.has_key('results'), '没有results关键字!') self.assertIsNotNone(data['results']['path'], '获取path失败!')
class StartPriview(unittest.TestCase): def setUp(self): CommomUtils.Connect() #正常情况 @parameterized.expand(CommomUtils.StartPreviewTestCaseFromExcel('startPreview')) def testStartPreview(self,_,param): HR=HttpRequest.HttpRequest() data = HR.open('camera._startPreview',fingerprint=Constant.fingerprint,parameters=param) print(data) self.assertIsNotNone(data,'获取data失败!data:%s'%data) self.assertTrue(data['state']=='done') self.assertTrue(data.has_key('results'), '获取results失败') previewUrl=data['results']['_previewUrl'] self.assertIsNotNone(previewUrl,'获取_previewUrl失败!') #如何验证rtmp连接是否正常打开 #表格异常情况,期望是错的,但目前是正常返回 @parameterized.expand(CommomUtils.StartPreviewTestCaseFromExcel('startPreview_err')) def testStartPreview_abnormalParam(self, _, param): # HR = HttpRequest.HttpRequest() # data = HR.open('camera._startPreview', parameters=param) # self.assertIsNotNone(data, '获取data失败!data:%s' % data) # self.assertTrue(data['state'] == 'exception') # self.assertTrue(data.has_key('error'), '获取error失败') HR=HttpRequest.HttpRequest() data = HR.open('camera._startPreview',fingerprint=Constant.fingerprint,parameters=param) self.assertIsNotNone(data,'获取data失败!data:%s'%data) self.assertTrue(data['state']=='done') self.assertTrue(data.has_key('results'), '获取results失败') previewUrl=data['results']['_previewUrl'] self.assertIsNot(previewUrl,'获取_previewUrl失败!') #多参数,只传一个参数等等 @parameterized.expand([ ( 'morepara',StartPreviewParam.StartPreview(stimime='h264', stiframe='30', stiwidth='1920', stibitrate='1000', stiheight='960', stimode='pano', orimime='h265', oriframe='30', oriwidth='1920', oribitrate='15000', oriheight='1440', saveori='false',aaaaa='bbbbbbb').getJsonData() ), ('only_one_para','"aaa":"bbbb"'), ('no_para','{}') ]) def testStartPreview_abnormalParaminTable(self, _, param): # HR = HttpRequest.HttpRequest() # data = HR.open('camera._startPreview', parameters=param) # self.assertIsNotNone(data, '获取data失败!data:%s' % data) # self.assertTrue(data['state'] == 'exception') # self.assertTrue(data.has_key('error'), '获取error失败') HR=HttpRequest.HttpRequest() data = HR.open('camera._startPreview',fingerprint=Constant.fingerprint,parameters=param) self.assertIsNotNone(data,'获取data失败!data:%s'%data) self.assertTrue(data['state']=='done') self.assertTrue(data.has_key('results'), '获取results失败') previewUrl=data['results']['_previewUrl'] self.assertIsNot(previewUrl,'获取_previewUrl失败!') #错误的Fingerprint def testStartPreview_otherabnormal(self): HR = HttpRequest.HttpRequest() param=StartPreviewParam.StartPreview(stimime='h264', stiframe='30', stiwidth='1920', stibitrate='1000', stiheight='960', stimode='pano', orimime='h265', oriframe='30', oriwidth='1920', oribitrate='15000', oriheight='1440', saveori='false').getJsonData() data = HR.open('camera._startPreview',fingerprint='',parameters=param) print(data) self.assertIsNotNone(data, '获取data失败!data:%s' % data) self.assertTrue(data['state'] == 'exception') self.assertTrue(data.has_key('error'), '获取error失败') '''
def testDisconneact_ok(self): CommomUtils.Connect() HR=HttpRequest.HttpRequest() data=HR.open("camera._disconnect") self.assertIsNotNone(data['state'],'state等于空!') self.assertTrue(data['state']=='done','state不等于done!')
msg['From']='*****@*****.**' msg['To']='*****@*****.**' msg['Subject']=Header('camera abnormal..'+Constant.ip,'utf-8') qqusrname='*****@*****.**' usrname='*****@*****.**' qqpwd='bcxkgzqlswhocbaa' smtpobj = smtplib.SMTP('smtp.qq.com', 587) smtpobj.starttls() # smtpobj = smtplib.SMTP('localhost') smtpobj.set_debuglevel(1) # smtpobj.sendmail('*****@*****.**','*****@*****.**',msg.as_string()) smtpobj.login(qqusrname, qqpwd) smtpobj.sendmail(usrname, usrname, msg.as_string()) smtpobj.quit() if __name__=='__main__': CommomUtils.Connect() HR = HttpRequest.HttpRequest() param = StartPreviewParam.StartPreview(stimime='h264', stiframe='30', stiwidth='1920', stibitrate='1000', stiheight='960', stimode='pano', orimime='h265', oriframe='30', oriwidth='1920', oribitrate='15000', oriheight='1440', saveori='false').getJsonData() preivewdata = HR.open('camera._startPreview', parameters=param) if(not preivewdata['state']=='done'): send(preivewdata+"") send('err')