def test_read_five_messages(self):
        rabbitmq = RabbitMQClient('', '', '', '', '', 'queue_name')

        msgs = [
            {'action': 'CREATE', 'type': 'vip', 'element': {}},
            {'action': 'CREATE', 'type': 'pool', 'element': {}},
            {'action': 'DELETE', 'type': 'pool', 'element': {}},
            {'action': 'UPDATE', 'type': 'pool', 'element': {}},
            {'action': 'UPDATE', 'type': 'vip', 'element': {}}
        ]
        rabbitmq.get_message = Mock(side_effect=msgs)
        msg_ret = rabbitmq.read_messages(3).next()

        self.assertEqual(len(msg_ret), 3)
        for i in range(3):
            self.assertDictEqual(msg_ret[i], msgs[i])

        msg_ret = rabbitmq.read_messages(3).next()

        self.assertEqual(len(msg_ret), 2)
        self.assertDictEqual(msg_ret[0], msgs[3])
        self.assertDictEqual(msg_ret[1], msgs[4])

        with self.assertRaises(StopIteration):
            rabbitmq.read_messages().next()
Exemplo n.º 2
0
    def test_get_message(self):
        msg = '{"action": "CREATE", "type": "vip", "element": {}}'

        self.pika_mock.basic_get.return_value = (MagicMock(), None, msg)
        rabbitmq = RabbitMQClient('', '', '', '', '', 'queue_name')

        message = rabbitmq.get_message()

        self.assertIsNotNone(message)
        self.pika_mock.basic_get.assert_called_once_with('queue_name')
    def test_get_message(self):
        msg = '{"action": "CREATE", "type": "vip", "element": {}}'

        self.pika_mock.basic_get.return_value = (MagicMock(), None, msg)
        rabbitmq = RabbitMQClient('', '', '', '', '', 'queue_name')

        message = rabbitmq.get_message()

        self.assertIsNotNone(message)
        self.pika_mock.basic_get.assert_called_once_with('queue_name')
Exemplo n.º 4
0
    def test_read_tree_messages(self):
        rabbitmq = RabbitMQClient('', '', '', '', '', 'queue_name')

        msgs = [{
            'action': 'CREATE',
            'type': 'vip',
            'element': {}
        }, {
            'action': 'CREATE',
            'type': 'pool',
            'element': {}
        }]
        rabbitmq.get_message = Mock(side_effect=msgs)
        msg_ret = rabbitmq.read_messages(3).next()

        self.assertEqual(len(msg_ret), 2)
        for i in range(2):
            self.assertDictEqual(msg_ret[i], msgs[i])

        with self.assertRaises(StopIteration):
            rabbitmq.read_messages().next()