Пример #1
0
 def test_empty_subscribe(self):
     c = PubSubClient()
     yield c.connect()
     try:
         yield c.pubsub_subscribe()
         raise Exception("ClientError not raised")
     except ClientError:
         pass
     c.disconnect()
Пример #2
0
 def test_issue17(self):
     c = PubSubClient()
     yield c.connect()
     res = yield c.pubsub_subscribe("foo")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     res = yield c.pubsub_unsubscribe()
     self.assertTrue(res)
     self.assertFalse(c.subscribed)
     c.disconnect()
Пример #3
0
 def test_empty_subscribe(self):
     c = PubSubClient()
     yield c.connect()
     try:
         yield c.pubsub_subscribe()
         raise Exception("ClientError not raised")
     except ClientError:
         pass
     c.disconnect()
Пример #4
0
 def test_issue17(self):
     c = PubSubClient()
     yield c.connect()
     res = yield c.pubsub_subscribe("foo")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     res = yield c.pubsub_unsubscribe()
     self.assertTrue(res)
     self.assertFalse(c.subscribed)
     c.disconnect()
Пример #5
0
 def test_empty_subscribe(self):
     c = PubSubClient()
     yield c.connect()
     res = yield c.pubsub_subscribe()
     self.assertFalse(res)
     c.disconnect()
Пример #6
0
 def test_pubsub(self):
     c = PubSubClient()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     try:
         yield c.pubsub_pop_message()
         raise Exception("exception not raised")
     except:
         pass
     res = yield c.pubsub_subscribe("foo1", "foo2")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     self.assertFalse(c2.subscribed)
     try:
         yield c.call("PING")
         raise Exception("exception not raised")
     except:
         pass
     res = yield c.pubsub_psubscribe("bar1*", "bar2*")
     self.assertTrue(res)
     tornado.ioloop.IOLoop.instance().add_future(self.publish(c2), None)
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value1")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value2")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value3")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value4")
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo1")
     yield c2.call("PUBLISH", "foo1", "value1")
     c2.disconnect()
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo2")
     yield c.pubsub_unsubscribe("foobar")
     yield c.pubsub_punsubscribe("foobar*")
     yield c.pubsub_punsubscribe("bar1*")
     yield c.pubsub_punsubscribe("bar2*")
     self.assertFalse(c.subscribed)
     c.disconnect()
Пример #7
0
 def test_subscribe_no_redis(self):
     c = PubSubClient()
     with mock.patch.object(c, "is_connected", return_value=False):
         res = yield c.pubsub_subscribe("foo")
         self.assertFalse(res)
         self.assertFalse(c.subscribed)
Пример #8
0
 def test_empty_subscribe(self):
     c = PubSubClient()
     yield c.connect()
     res = yield c.pubsub_subscribe()
     self.assertFalse(res)
     c.disconnect()
Пример #9
0
 def test_pubsub(self):
     c = PubSubClient()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     try:
         yield c.pubsub_pop_message()
         raise Exception("exception not raised")
     except Exception:
         pass
     res = yield c.pubsub_subscribe("foo1", "foo2")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     self.assertFalse(c2.subscribed)
     try:
         yield c.call("PING")
         raise Exception("exception not raised")
     except Exception:
         pass
     res = yield c.pubsub_psubscribe("bar1*", "bar2*")
     self.assertTrue(res)
     tornado.ioloop.IOLoop.instance().add_future(self.publish(c2), None)
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value1")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value2")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value3")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value4")
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo1")
     yield c2.call("PUBLISH", "foo1", "value1")
     c2.disconnect()
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo2")
     yield c.pubsub_unsubscribe("foobar")
     yield c.pubsub_punsubscribe("foobar*")
     yield c.pubsub_punsubscribe("bar1*")
     yield c.pubsub_punsubscribe("bar2*")
     self.assertFalse(c.subscribed)
     c.disconnect()
Пример #10
0
 def test_subscribe_no_redis(self):
     c = PubSubClient()
     with mock.patch.object(c, "is_connected", return_value=False):
         res = yield c.pubsub_subscribe("foo")
         self.assertFalse(res)
         self.assertFalse(c.subscribed)