作者在 2016-06-23 17:54:05 发布以下内容
#encoding: utf-8
import sys, unittest, xmlrpclib, time, socket, select, multiprocessing , random
from main import database
import esl_init
from main import create_task_data
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import os
from xml.dom import minidom
#esl = esl_init.ESL()
server = xmlrpclib.ServerProxy('http://127.0.0.1:9000')
db = database.DB()
def CleanUpLog():
with open("./log.txt","w") as f:
pass
def bind(type,eslid,eslidid,salesno,salesid,apid,apidid):
ret,val = server.send_cmd(type, [{eslid:eslidid,salesno:salesid, apid:apidid}])
print ret,val
return ret,val
def unbind(type,eslid,eslidid,template,unbind):
ret,val = server.send_cmd(type, [{eslid:eslidid,template:unbind}])
print ret,val
# print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
# bind("BIND","eslid","5C-84-32-99","salesno","100001","apid","165")
# time.sleep(60)
# print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
# unbind("UNBIND","eslid","5C-84-32-99","template","unbind")
# time.sleep(20)
# print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
#######################################################################
class ReadXml(object):
def ReadXml(self,filename,elementfirstnode,num,elementsecondnode):
dom = minidom.parse(filename)
root = dom.documentElement
parnote = root.getElementsByTagName(elementfirstnode)[num]
secondnote = parnote.getElementsByTagName(elementsecondnode)[0].childNodes[0].nodeValue
return secondnote
def Send(self,type,cmd): #發送命令,發送這個命令
ret,val = server.send_cmd(type,cmd)
# print ret,val[0]['bak']
# a = val[0]["bak"]
return ret,val
# P = ReadXml()
# s = '[{"apid":"165"}]'
# P.Send("AP_INFO",eval(s))
# print server.send_cmd("AP_INFO", [{"apid":"165"}])
class bruceLee(unittest.TestCase):
def setUp(self):
global P
P = ReadXml()
print "start"
def tearDown(self):
print "exit"
def testA(self):
a = P.ReadXml(r"D:\s.xml", "testdata", 0, "send_cmd0")
print a #节点为send_cmd0
ret,val = P.Send(P.ReadXml(r"D:\s.xml", "testdata", 0, "type"),eval(a)) #发送命令后的返回值
print ret,val[0]['bak'] # 系统返回的
# self.assertEqual("OK",P.Send("AP_INFO",eval(P.ReadXml(r"D:\s.xml", "testdata", 0, "send_cmd0"))))
#self.assertTrue(m.lujingzhi("id",yang.denglu2("xml.xml", "kejian1", 0,"shuxing0")).is_displayed())
self.assertEqual(P.ReadXml(r"D:\s.xml", "testdata", 0, "act0"),val[0]['bak'])
unittest.main()
# a = eval('[{"bind":[],"ap_status":[],"group":[],"transmission":[]}]')
# print type(a)
# print a
<?xml version="1.0" encoding="utf-8"?>
<api>
<testdata>
<type>AP_INFO</type>
<send_cmd0>[{"apid":"165"}]</send_cmd0>
<act0>00</act0>
<send_cmd1></send_cmd1>
<act1>OK</act1>
<send_cmd2></send_cmd2>
<act2>OK</act2>
<send_cmd3></send_cmd3>
<act3>OK</act3>
<send_cmd4></send_cmd4>
<act4>OK</act4>
<send_cmd5></send_cmd5>
<act5>OK</act5>
<send_cmd6></send_cmd6>
<act6>OK</act6>
</testdata>
</api>