Esempio n. 1
0
class TestPubSubscribe(unittest.TestCase):
    def onMessage(self, message):
        self.assertTrue(len(message.payload_objects) > 0)
        msg_body = message.payload_objects[0].content
        self.assertIn(msg_body, MESSAGES)
        self.counter += 1
        if self.counter == len(MESSAGES):
            self.semaphore.release()

    def setUp(self):
        self.counter = 0
        self.semaphore = Semaphore(0)
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)
        self.bw_client.subscribe(URI, self.onMessage)

    def tearDown(self):
        self.bw_client.close()

    def testPublishSubscribe(self):
        for msg in MESSAGES:
            po = PayloadObject((64, 0, 0, 0), None, msg)
            self.bw_client.publish(URI, payload_objects=(po, ))
        self.semaphore.acquire()
Esempio n. 2
0
class TestListQuery(unittest.TestCase):
    def setUp(self):
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)

    def tearDown(self):
        self.bw_client.close()

    def testListQuery(self):
        for planet, probe in PERSISTED_DATA.items():
            po = PayloadObject((64, 0, 0, 0), None, probe)
            uri = BASE_URI + "/persisted/" + planet
            self.bw_client.publish(uri, payload_objects=(po, ), persist=True)

        results = self.bw_client.query(BASE_URI + "/persisted/+")
        self.assertEquals(len(results), len(PERSISTED_DATA))
        probes = [result.payload_objects[0].content for result in results]
        self.assertTrue(
            all([probe in PERSISTED_DATA.values() for probe in probes]))

        children = self.bw_client.list(BASE_URI + "/persisted")
        self.assertEquals(len(children), len(PERSISTED_DATA))
        planets = [child[child.rfind("/") + 1:] for child in children]
        self.assertTrue(
            all([planet in PERSISTED_DATA.keys() for planet in planets]))
class TestPubSubscribe(unittest.TestCase):
    def onMessage(self, message):
        self.assertTrue(len(message.payload_objects) > 0)
        msg_body = message.payload_objects[0].content
        self.assertIn(msg_body, MESSAGES)
        self.counter += 1
        if self.counter == len(MESSAGES):
            self.semaphore.release()

    def setUp(self):
        self.counter = 0
        self.semaphore = Semaphore(0)
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)
        self.bw_client.subscribe(URI, self.onMessage)

    def tearDown(self):
        self.bw_client.close()

    def testPublishSubscribe(self):
        for msg in MESSAGES:
            po = PayloadObject((64, 0, 0, 0), None, msg)
            self.bw_client.publish(URI, payload_objects=(po,))
        self.semaphore.acquire()
class TestListQuery(unittest.TestCase):
    def onSetEntityResponse(self, response):
        self.assertEqual("okay", response.status)
        self.semaphore.release()

    def assertOkay(self, response):
        self.assertEqual("okay", response.status)

    def onMessage(self, message):
        if message.getFirstValue("finished") != "true":
            self.assertTrue(len(message.payload_objects) > 0)
            msg_body = message.payload_objects[0].content
            self.assertIn(msg_body, PERSISTED_DATA.values())
            self.counter += 1
        else:
            self.assertEqual(self.counter, len(PERSISTED_DATA))
            self.semaphore.release()

    def onListResult(self, child):
        if child is not None:
            planet = child[child.rfind("/") + 1:]
            self.assertIn(planet, PERSISTED_DATA.keys())
            self.counter += 1
        else:
            self.assertEqual(self.counter, len(PERSISTED_DATA))
            self.semaphore.release()

    def setUp(self):
        self.counter = 0
        self.semaphore = Semaphore(0)
        self.bw_client = Client()
        self.bw_client.asyncSetEntityFromFile(KEY_FILE,
                                              self.onSetEntityResponse)
        self.bw_client.overrideAutoChainTo(True)
        self.semaphore.acquire()

    def tearDown(self):
        self.bw_client.close()

    def testListQuery(self):
        for planet, probe in PERSISTED_DATA.items():
            po = PayloadObject((64, 0, 0, 0), None, probe)
            uri = BASE_URI + "/persisted/" + planet
            self.bw_client.asyncPublish(uri,
                                        self.assertOkay,
                                        payload_objects=(po, ),
                                        persist=True)
        self.bw_client.asyncQuery(BASE_URI + "/persisted/+", self.assertOkay,
                                  self.onMessage)
        self.semaphore.acquire()

        self.counter = 0
        self.bw_client.asyncList(BASE_URI + "/persisted", self.assertOkay,
                                 self.onListResult)
        self.semaphore.acquire()
class TestListQuery(unittest.TestCase):
    def onSetEntityResponse(self, response):
        self.assertEqual("okay", response.status)
        self.semaphore.release()

    def assertOkay(self, response):
        self.assertEqual("okay", response.status)

    def onMessage(self, message):
        if message.getFirstValue("finished") != "true":
            self.assertTrue(len(message.payload_objects) > 0)
            msg_body = message.payload_objects[0].content
            self.assertIn(msg_body, PERSISTED_DATA.values())
            self.counter += 1
        else:
            self.assertEqual(self.counter, len(PERSISTED_DATA))
            self.semaphore.release()

    def onListResult(self, child):
        if child is not None:
            planet = child[child.rfind("/")+1:]
            self.assertIn(planet, PERSISTED_DATA.keys())
            self.counter += 1
        else:
            self.assertEqual(self.counter, len(PERSISTED_DATA))
            self.semaphore.release()

    def setUp(self):
        self.counter = 0
        self.semaphore = Semaphore(0)
        self.bw_client = Client()
        self.bw_client.asyncSetEntityFromFile(KEY_FILE, self.onSetEntityResponse)
        self.bw_client.overrideAutoChainTo(True)
        self.semaphore.acquire()

    def tearDown(self):
        self.bw_client.close()

    def testListQuery(self):
        for planet, probe in PERSISTED_DATA.items():
            po = PayloadObject((64, 0, 0, 0), None, probe)
            uri = BASE_URI + "/persisted/" + planet
            self.bw_client.asyncPublish(uri, self.assertOkay, payload_objects=(po,), persist=True)
        self.bw_client.asyncQuery(BASE_URI + "/persisted/+", self.assertOkay, self.onMessage)
        self.semaphore.acquire()

        self.counter = 0
        self.bw_client.asyncList(BASE_URI + "/persisted", self.assertOkay, self.onListResult)
        self.semaphore.acquire()
Esempio n. 6
0
class TestPubSubFailure(unittest.TestCase):
    def setUp(self):
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)

    def tearDown(self):
        self.bw_client.close()

    def testQueryFailure(self):
        with self.assertRaises(RuntimeError):
            # Unit test key should not have permissions on this URI
            self.bw_client.query("jkolb/test")

    def testListFailure(self):
        with self.assertRaises(RuntimeError):
            # Unit test key should not have permissions on this URI
            self.bw_client.list("jkolb/test")
Esempio n. 7
0
class TestPubSubFailure(unittest.TestCase):
    def onMessage(self, message):
        pass

    def setUp(self):
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)

    def tearDown(self):
        self.bw_client.close()

    def testSubscribeFailure(self):
        with self.assertRaises(RuntimeError):
            # Unit test key should not have permissions on this URI
            self.bw_client.subscribe("jkolb/test", self.onMessage)

    def testPublishFailure(self):
        with self.assertRaises(RuntimeError):
            # Unit test key should not have permissions on this URI
            po = PayloadObject(ponames.PODFText, None, "Hello, World!")
            self.bw_client.publish("jkolb/test", payload_objects=(po, ))
class TestPubSubFailure(unittest.TestCase):
    def onMessage(self, message):
        pass

    def setUp(self):
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)

    def tearDown(self):
        self.bw_client.close()

    def testSubscribeFailure(self):
        with self.assertRaises(RuntimeError):
            # Unit test key should not have permissions on this URI
            self.bw_client.subscribe("jkolb/test", self.onMessage)

    def testPublishFailure(self):
        with self.assertRaises(RuntimeError):
            # Unit test key should not have permissions on this URI
            po = PayloadObject(ponames.PODFText, None, "Hello, World!")
            self.bw_client.publish("jkolb/test", payload_objects=(po,))
class TestListQuery(unittest.TestCase):
    def setUp(self):
        self.bw_client = Client()
        self.bw_client.setEntityFromFile(KEY_FILE)
        self.bw_client.overrideAutoChainTo(True)

    def tearDown(self):
        self.bw_client.close()

    def testListQuery(self):
        for planet, probe in PERSISTED_DATA.items():
            po = PayloadObject((64, 0, 0, 0), None, probe)
            uri = BASE_URI + "/persisted/" + planet
            self.bw_client.publish(uri, payload_objects=(po,), persist=True)

        results = self.bw_client.query(BASE_URI + "/persisted/+")
        self.assertEquals(len(results), len(PERSISTED_DATA))
        probes = [result.payload_objects[0].content for result in results]
        self.assertTrue(all([probe in PERSISTED_DATA.values() for probe in probes]))

        children = self.bw_client.list(BASE_URI + "/persisted")
        self.assertEquals(len(children), len(PERSISTED_DATA))
        planets = [child[child.rfind("/")+1:] for child in children]
        self.assertTrue(all([planet in PERSISTED_DATA.keys() for planet in planets]))