def test_bindLite(self): u'''step1: 发送绑定lite播放器命令''' '''获取token,存入配置文件''' vnnox_url = getConf("constant", "vnnoxlite_url") username = getConf("constant", "vnnoxlite_username") password = getConf("constant", "vnnoxlite_password") response = rq_Logon(vnnox_url=vnnox_url,username=username,password=password) self.assertTrue(10106001 in response["status"],"获取token失败") setConf("data","token",response["data"]["token"]) '''获取player相关信息''' response = rq_profile(url=vnnox_url,token=response["data"]["token"]) print response vnnoxLite_play_user = response["data"]["playerAuthUsername"] vnnoxLite_play_password = response["data"]["playerClientSecret"] vnnoxLite_player_url = response["data"]["playerConnectionUrl"] '''绑定lite''' bind_vnnoxLite(self,Server_address=vnnoxLite_player_url,username=vnnoxLite_play_user,password=vnnoxLite_play_password) time.sleep(3) print "验证绑定结果,并将已绑定播放器存入配置文件" assertBindInfo(self,vnnoxLite_player_url,vnnoxLite_play_user) self.assertTrue(self.isLoginAll,"有未登陆的终端")
def searchT(self=None): if not self: removeSection("searchRes") addSection("searchRes") setConf("data","bad_sn","") print "search and login terminal" buffer = getPacket(type=-30635,param1=0x81) t = threading.Thread(target=udp_receive_data,args=(self,)) t.start() time.sleep(1) udp_send_data(buffer) t.join() if getConf("data","bad_sn"): return False else: return True
def test_publish(self): '''获取第一个节目''' response = rq_program(search='', offset=1, limit=20, sort='update_time', sortType='desc') print response u'check' self.assertTrue(response["status"] == [10000001], 'lite获取节目失败') print response["data"]["programList"][0]["id"] setConf("data", "program_id", response["data"]["programList"][0]["id"]) program_id = response["data"]["programList"][0]["id"] '''发布 vnnoxLite节目 ''' player_ids = json.loads(getConf("data", "lite_player")).values() response = rq_generatePlan(player_id=player_ids,program_id=program_id) print response u'check' self.assertTrue(response["status"] == [110250010101] ,'lite发布节目失败')
def assertBindInfo(self, vnnoxLite_player_url, vnnoxLite_play_user): '''通过终端检验''' flag = True result = getBindInfo(self) print result for sn in result.keys(): info = result[sn] if info in [Constant.ERROR, Constant.FAILED, Constant.NOAPPLY]: print sn + "获取绑定信息失败" flag = False elif not info["isBind"]: print sn + "未绑定" flag = False elif info["baseUrl"] != vnnoxLite_player_url or info[ "username"] != vnnoxLite_play_user: print sn + "已绑定,但绑定信息与配置文件不符" flag = False '''在vnnox端检验''' flag1 = True res = rq_PlayerProgramProgress(url=getConf("constant", "vnnoxlite_url")) print res binded_player = {} for i in res["data"]: binded_player[i["name"].encode("utf-8")] = i["id"].encode("utf-8") lite_player = {} for sn in self.sns: aliasName = json.loads(getConf("searchRes", sn))["aliasName"].encode("utf-8") if aliasName in binded_player.keys(): lite_player[aliasName] = binded_player[aliasName] else: flag1 = False print aliasName + "未在vnnoxlite注册成功" '''将player_id写入配置文件''' setConf("data", "lite_player", json.dumps(lite_player)) if flag and flag1: print "全部绑定成功" self.assertTrue(flag and flag1, "未全部绑定成功")
def udp_receive_data(self): s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1) hostname = socket.gethostname() ip = socket.gethostbyname(hostname) s.settimeout(6) s.bind((ip, Constant.UDP_HAND_LISTEN_PORT)) data = getConf("data","sn") if self: self.searchRes = {} if data : sns = data.split(",") while True: try: data, address = s.recvfrom(1024) a = data[24:] info = json.loads(a) info["addr"] = address[0] strn = json.dumps(info) sn = info["sn"].encode('utf-8').lower() for i in sns: if i in sn: if self: self.searchRes[sn] = info else: setConf("searchRes",sn,strn) sns.remove(i) break if not sns: return except socket.timeout: s.close() if sns: if self: return print "未搜索到屏体:" + str(sns) setConf("data","bad_sn",str(sns)) return else: while True: try: data, address = s.recvfrom(1024) a = data[24:] info = json.loads(a) info["addr"] = address[0] strn = json.dumps(info) sn = info["sn"].encode('utf-8').lower() if self: self.searchRes[sn] = info else: setConf("searchRes", sn, strn) except socket.timeout: s.close() return
def update(self, type="", sns=None): if type == "APP": UPath = os.path.abspath("../file/update/APP") for i in os.listdir(UPath): if "UPDATE_APP" in i: filename = i elif type == "OS3128": UPath = os.path.abspath("../file/update/OS3128") for i in os.listdir(UPath): if "UPDATE_OS" in i: filename = i elif type == "OS3368": UPath = os.path.abspath("../file/update/OS3368") for i in os.listdir(UPath): if "UPDATE_OS" in i: filename = i else: raise RuntimeError("update方法的type参数有误") if not filename: print "升级文件目录下没有" + type + "升级包" return False filepath = UPath + "/" + filename source = "/cache/" + filename '''上传升级文件''' flag = uploadFile(self, user="******", file=filepath, ftpdir="", sns=sns) if flag: print type + "升级文件全部上传成功" else: print type + "升级文件未全部上传成功" if type == "APP": version = re.findall(r"UPDATE_APP_(.+?).nuzip", filename)[0] setConf("data", "appversion", version) elif type == "OS3128": version = re.findall(r"UPDATE_OS_(.+?).nuzip", filename)[0] setConf("data", "os3128version", version) elif type == "OS3368": version = re.findall(r"UPDATE_OS_(.+?).nuzip", filename)[0] setConf("data", "os3368version", version) size = os.path.getsize(filepath) md5 = getFileMd5(filepath) data = {} data["type"] = "UPDATE" data["source"] = {"type": 0, "platform": 1} tasks = [] task = {} task["packageType"] = "NUZIP" task["version"] = version task["executionType"] = "IMMEDIATELY" if type == "APP": task["updateType"] = "UPDATE" task["startupAfterInstalled"] = True task["startupAfterBoot"] = True task["conditions"] = [] task["source"] = source task["size"] = int(size) task["md5"] = md5 tasks.append(task) data["tasks"] = tasks print data result = sendSetCommand(self, Constant.WHAT_UPDATE, 0, Constant.ACTION_UPDATE, 0, sns=sns, data=data, timeout=120, describe=type + "升级命令") return result
runner = HTMLTestRunner(stream=stream, title=u"终端自动化测试报告", description=u"用例执行情况", verbosity=2) runner.run(discover) stream.close() if __name__ == "__main__": parse = argparse.ArgumentParser(description="terminal test") parse.add_argument('-sn', nargs='?', type=str, help="sn,eg: 256,3456,12212") parse.add_argument('-password', nargs='?', type=str, help="input password") parse.add_argument('-email', nargs='?', type=str, help="input email") args = parse.parse_args() if args.sn: setConf("constant", "data", args.sn) else: setConf("constant", "data", '') if args.password: setConf("constant", "login_password", args.password) # else: # setConf("constant", "login_password", '123456') if args.email: setConf("constant", "email", args.email) else: setConf("constant", "email", '*****@*****.**') # flag = searchT() # if not flag: # raise RuntimeError("有未搜到的终端")
runner.run(discover) stream.close() if __name__ == "__main__": parse = argparse.ArgumentParser(description="terminal test") parse.add_argument('-sn', nargs='?', type=str, help="sn,eg: 256,3456,12212") parse.add_argument('-password', nargs='?', type=str, help="input password") parse.add_argument('-email', nargs='?', type=str, help="input email") args = parse.parse_args() if args.sn: setConf("constant", "data", args.sn) else: setConf("constant", "data", '') if args.password: setConf("constant", "login_password", args.password) # else: # setConf("constant", "login_password", '123456') if args.email: setConf("constant", "email", args.email) else: setConf("constant", "email", '*****@*****.**') # flag = searchT() # if not flag: # raise RuntimeError("有未搜到的终端")