Ejemplo n.º 1
0
 def setUp(self):
     super(TestLeaf, self).setUp()
     self._createProcess(notifyOut)
     self._initXMPP(config.NOTIFYIN, config.NOTIFYIN_PASS, config.ROOT_SERVER_NAME)
     self.leaf = Leaf(
         testmode=True,
         testcom=[
             ("COM6", script.ME_WAVECOMGSM, "1234567890"),
             ("COM26", script.ME_SIEMENSC55, "1234567890"),
             ("COM27", script.ME_NOKIA6235I, "1234567890"),
         ],
     )
     self.leafsvr = "leaf_server@{0}/{1}".format(lconf.MSG_SERVER, lconf.SERVERNAME)
Ejemplo n.º 2
0
class TestLeaf(TestCoreComponent):
    def setUp(self):
        super(TestLeaf, self).setUp()
        self._createProcess(notifyOut)
        self._initXMPP(config.NOTIFYIN, config.NOTIFYIN_PASS, config.ROOT_SERVER_NAME)
        self.leaf = Leaf(
            testmode=True,
            testcom=[
                ("COM6", script.ME_WAVECOMGSM, "1234567890"),
                ("COM26", script.ME_SIEMENSC55, "1234567890"),
                ("COM27", script.ME_NOKIA6235I, "1234567890"),
            ],
        )
        self.leafsvr = "leaf_server@{0}/{1}".format(lconf.MSG_SERVER, lconf.SERVERNAME)

    # ----------------------
    def tearDown(self):
        self.leaf.shutdown()
        super(TestLeaf, self).tearDown()

    # ----------------------
    def runTest(self):
        test_function = [x for x in dir(self) if x[:6] == "srtest"]
        map(lambda x: getattr(self, x)(), sorted(test_function))

    # ----------------------
    def srtest10_sms(self):
        self.bc.sendMessage(
            self.leafsvr, "SMSG", "COM27,sms://08569886868,Graww.. Horeeee berhasil booo!!!! Yeehaaww!!."
        )
        self.leaf.processMessage()
        x = self.getQueue("COM27").get_nowait()
        # print x
        self.assertTrue("/C=27 /" in x["ttl"])
        self.assertTrue("'AT+CMGS=" in x["ttl"])

        self.bc.sendMessage(
            self.leafsvr, "JBDV", "COM26,99,sms://08569886868,Graww.. Horeeee berhasil booo!!!! Yeehaaww!!."
        )
        self.leaf.processMessage()
        x = self.getQueue("COM26").get_nowait()
        # print x
        self.assertTrue("/C=26 /" in x["ttl"])
        self.assertTrue("'AT+CMGS=" in x["ttl"])
        self.assertTrue("wait '>'" in x["ttl"])

    # ----------------------
    def srtest20_ussd(self):
        self.bc.sendMessage(self.leafsvr, "JBDV", "COM6,90,ussd://*677*<dest>*100*<pin>#")
        self.leaf.processMessage()
        x = self.getQueue("COM6").get_nowait()
        # print x
        self.assertTrue("/C=6 /" in x["ttl"])
        self.assertTrue("'AT+CUSD=1," in x["ttl"])

    # ----------------------
    def srtest30_data(self):
        self.bc.sendMessage(self.leafsvr, "JBDV", "COM26,199,data://15.50000..0816999999..1234$")
        self.leaf.processMessage()
        x = self.getQueue("COM26").get_nowait()
        # print x
        self.assertTrue("/C=26 /" in x["ttl"])
        self.assertTrue("'AT+CKPD=" in x["ttl"])

        self.bc.sendMessage(self.leafsvr, "JBDV", "COM6,199,data://15.50000..0816999999..1234$")
        # time.sleep(1)
        self.leaf.processMessage()
        x = self.getQueue("COM6").get_nowait()
        # print x
        self.assertTrue("/C=6 /" in x["ttl"])
        self.assertTrue("'AT+STGI=0'" in x["ttl"])

    # ----------------------
    def srxtest40_benchmark(self):
        from datetime import datetime

        print self.leaf._convertDataToSTK("15.50000..0816999999..1234$")
        start = datetime.now()
        for i in range(10000):
            self.leaf._convertDataToSTK("15.50000..0816999999..1234$")
        print datetime.now() - start

    # ----------------------
    def srtest50_LAWK(self):
        threading.Thread(target=self.leaf._LeafWakeup).start()
        msg = self._waitForMessage(3)
        # print msg
        self.assertTrue("[email protected]/SERVER1:LAWK=" in msg)

    # ----------------------
    def srtest60_DVLS(self):
        self.bc.sendMessage(self.leafsvr, "RDVL", "*")
        self.leaf.processMessage()
        msg = self._waitForMessage(3)
        _, param = msg.split("=", 1)
        devices = cPickle.loads(zlib.decompress(base64.b64decode(param)))
        self.assertEqual(len(devices), 3)
        self.assertEqual(devices[0]["imei"], "1234567890")

    # ----------------------
    def srtest70_DVWK(self):
        self.bc.sendMessage(self.leafsvr, "DVRS", "COM27")
        self.leaf.processMessage()
        x = self.leaf.result_q.get(1, 1)
        # print x
        self.assertTrue(isinstance(x["result"], dict))

    # ----------------------
    def getQueue(self, port):
        return self.leaf.root[port]["queue"]