Exemplo n.º 1
0
 def setUp(self):
     super(RedisEngineTest, self).setUp()
     self.application = Application(**{'options': Options})
     self.engine = RedisEngine(self.application, io_loop=self.io_loop)
     self.engine.initialize()
     self.engine.history_size = 2
     self.engine.presence_timeout = 1
     self.project_id = "project_id"
     self.channel = "channel"
     self.uid_1 = 'uid-1'
     self.uid_2 = 'uid-2'
     self.user_id = 'user_id'
     self.user_id_extra = 'user_id_extra'
     self.user_info = "{}"
     self.message_1 = json.dumps('test message 1')
     self.message_2 = json.dumps('test message 2')
     self.message_3 = json.dumps('test message 3')
Exemplo n.º 2
0
 def setUp(self):
     super(RedisEngineTest, self).setUp()
     self.application = Application(**{'options': Options})
     self.engine = RedisEngine(self.application, io_loop=self.io_loop)
     self.engine.initialize()
     self.engine.history_size = 2
     self.engine.presence_timeout = 1
     self.project_id = "project_id"
     self.channel = "channel"
     self.uid_1 = 'uid-1'
     self.uid_2 = 'uid-2'
     self.user_id = 'user_id'
     self.user_id_extra = 'user_id_extra'
     self.user_info = "{}"
     self.message_1 = json.dumps('test message 1')
     self.message_2 = json.dumps('test message 2')
     self.message_3 = json.dumps('test message 3')
Exemplo n.º 3
0
class RedisEngineTest(AsyncTestCase):
    """ Test the client """

    def setUp(self):
        super(RedisEngineTest, self).setUp()
        self.application = Application(**{'options': Options})
        self.engine = RedisEngine(self.application, io_loop=self.io_loop)
        self.engine.initialize()
        self.engine.history_size = 2
        self.engine.presence_timeout = 1
        self.project_id = "project_id"
        self.channel = "channel"
        self.uid_1 = 'uid-1'
        self.uid_2 = 'uid-2'
        self.user_id = 'user_id'
        self.user_id_extra = 'user_id_extra'
        self.user_info = "{}"
        self.message_1 = json.dumps('test message 1')
        self.message_2 = json.dumps('test message 2')
        self.message_3 = json.dumps('test message 3')

    @gen_test
    def test_presence(self):

        result = yield Task(self.engine.worker.flushdb)
        self.assertEqual(result, "OK")

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertEqual(result, {})

        result, error = yield self.engine.add_presence(
            self.project_id, self.channel,
            self.uid_1, self.user_info
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)

        result, error = yield self.engine.add_presence(
            self.project_id, self.channel,
            self.uid_1, self.user_info
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)
        self.assertEqual(len(result), 1)

        result, error = yield self.engine.add_presence(
            self.project_id, self.channel,
            self.uid_2, self.user_info
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)
        self.assertTrue(self.uid_2 in result)
        self.assertEqual(len(result), 2)

        result, error = yield self.engine.remove_presence(
            self.project_id, self.channel, self.uid_2
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)
        self.assertTrue(self.uid_2 not in result)
        self.assertEqual(len(result), 1)

        time.sleep(2)
        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertEqual(result, {})

    @gen_test
    def test_history(self):
        result = yield Task(self.engine.worker.flushdb)
        self.assertEqual(result, "OK")

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_1
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 1)

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_2
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 2)

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_3
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 2)

    @gen_test
    def test_history_expire(self):
        result = yield Task(self.engine.worker.flushdb)
        self.assertEqual(result, "OK")

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_1, history_expire=1
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 1)

        time.sleep(2)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 0)
Exemplo n.º 4
0
class RedisEngineTest(AsyncTestCase):
    """ Test the client """

    def setUp(self):
        super(RedisEngineTest, self).setUp()
        self.application = Application(**{'options': Options})
        self.engine = RedisEngine(self.application, io_loop=self.io_loop)
        self.engine.initialize()
        self.engine.history_size = 2
        self.engine.presence_timeout = 1
        self.project_id = "project_id"
        self.channel = "channel"
        self.uid_1 = 'uid-1'
        self.uid_2 = 'uid-2'
        self.user_id = 'user_id'
        self.user_id_extra = 'user_id_extra'
        self.user_info = "{}"
        self.message_1 = json.dumps('test message 1')
        self.message_2 = json.dumps('test message 2')
        self.message_3 = json.dumps('test message 3')

    @gen_test
    def test_presence(self):

        result = yield Task(self.engine.worker.flushdb)
        self.assertEqual(result, b"OK")

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertEqual(result, {})

        result, error = yield self.engine.add_presence(
            self.project_id, self.channel,
            self.uid_1, self.user_info
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)

        result, error = yield self.engine.add_presence(
            self.project_id, self.channel,
            self.uid_1, self.user_info
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)
        self.assertEqual(len(result), 1)

        result, error = yield self.engine.add_presence(
            self.project_id, self.channel,
            self.uid_2, self.user_info
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)
        self.assertTrue(self.uid_2 in result)
        self.assertEqual(len(result), 2)

        result, error = yield self.engine.remove_presence(
            self.project_id, self.channel, self.uid_2
        )
        self.assertEqual(result, True)

        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertTrue(self.uid_1 in result)
        self.assertTrue(self.uid_2 not in result)
        self.assertEqual(len(result), 1)

        time.sleep(2)
        result, error = yield self.engine.get_presence(
            self.project_id, self.channel
        )
        self.assertEqual(result, {})

    @gen_test
    def test_history(self):
        result = yield Task(self.engine.worker.flushdb)
        self.assertEqual(result, b"OK")

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_1, history_size=2, history_lifetime=1
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 1)

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_2, history_size=2, history_lifetime=1
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 2)

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_3, history_size=2, history_lifetime=1
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 2)

    @gen_test
    def test_history_expire(self):
        result = yield Task(self.engine.worker.flushdb)
        self.assertEqual(result, b"OK")

        result, error = yield self.engine.add_history_message(
            self.project_id, self.channel, self.message_1, history_lifetime=1, history_size=2
        )
        self.assertEqual(error, None)
        self.assertEqual(result, True)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 1)

        time.sleep(2)

        result, error = yield self.engine.get_history(
            self.project_id, self.channel
        )
        self.assertEqual(error, None)
        self.assertEqual(len(result), 0)