示例#1
0
    def test_read_messages(self):
        msg = '{"action": "CREATE", "type": "vip", "element": {}}'

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

        for i in range(3):
            msg_ret = rabbitmq.read_messages().next()
            self.assertDictEqual(msg_ret[0], json.loads(msg))
    def test_read_messages(self):
        msg = '{"action": "CREATE", "type": "vip", "element": {}}'

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

        for i in range(3):
            msg_ret = rabbitmq.read_messages().next()
            self.assertDictEqual(msg_ret[0], json.loads(msg))
示例#3
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')
示例#4
0
    def test_stop_read_messages(self):

        pika_mock = self._mock_pika()
        pika_mock.basic_get.return_value = (None, None, None)

        rabbitmq = RabbitMQClient('localhost', 5672, 'user', 'password', '/',
                                  'queue_name')

        with self.assertRaises(StopIteration):
            rabbitmq.read_messages().next()
    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_stop_read_messages(self):

        pika_mock = self._mock_pika()
        pika_mock.basic_get.return_value = (None, None, None)

        rabbitmq = RabbitMQClient(
            'localhost', 5672, 'user', 'password', '/', 'queue_name')

        with self.assertRaises(StopIteration):
            rabbitmq.read_messages().next()
    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()
示例#8
0
    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()
示例#9
0
    def test_nack_message(self):
        rabbitmq = RabbitMQClient('', '', '', '', '', 'queue_name')

        rabbitmq.nack_message(1)
        self.pika_mock.basic_nack.assert_called_once_with(1)