コード例 #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))
コード例 #2
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()
コード例 #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_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()
コード例 #5
0
    def test_nack_message(self):
        rabbitmq = RabbitMQClient('', '', '', '', '', 'queue_name')

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