Ejemplo n.º 1
0
    def test_preserves_messages(self, mock_message_handler, mock_get_messages):
        queue_name = 'my-queue'
        queue = mock.MagicMock()

        mock_get_messages.return_value = [mock.MagicMock()]
        mock_message_handler.side_effect = Exception

        fetch_and_process_messages(queue_name, queue)

        mock_get_messages.return_value[0].delete.assert_not_called()
Ejemplo n.º 2
0
    def test_pre_process_hook(self, mock_message_handler, mock_get_messages,
                              settings):
        queue_name = 'my-queue'
        queue = mock.MagicMock()
        settings.HEDWIG_PRE_PROCESS_HOOK = 'tests.test_consumer.pre_process_hook'

        mock_get_messages.return_value = [mock.MagicMock(), mock.MagicMock()]

        fetch_and_process_messages(queue_name, queue)

        pre_process_hook.assert_has_calls([
            mock.call(sqs_queue_message=x)
            for x in mock_get_messages.return_value
        ])
Ejemplo n.º 3
0
    def test_ignore_delete_error(self, mock_message_handler,
                                 mock_get_messages):
        queue_name = 'my-queue'
        queue = mock.MagicMock()

        mock_get_messages.return_value = [mock.MagicMock()]
        mock_get_messages.return_value[0].delete.side_effect = Exception

        with mock.patch.object(consumer.logger, 'exception') as logging_mock:
            fetch_and_process_messages(queue_name, queue)

            logging_mock.assert_called_once()

        mock_get_messages.return_value[0].delete.assert_called_once_with()
Ejemplo n.º 4
0
    def test_special_handling_retry_error(self, mock_message_handler,
                                          mock_get_messages):
        queue_name = 'my-queue'
        queue = mock.MagicMock()

        mock_get_messages.return_value = [mock.MagicMock()]
        mock_message_handler.side_effect = RetryException

        with mock.patch.object(consumer.logger, 'info') as logging_mock:
            fetch_and_process_messages(queue_name, queue)

            logging_mock.assert_called_once()

        mock_get_messages.return_value[0].delete.assert_not_called()
Ejemplo n.º 5
0
    def test_success(self, mock_message_handler, mock_get_messages):
        queue_name = 'my-queue'
        queue = mock.MagicMock()
        num_messages = 3
        visibility_timeout = 4

        mock_get_messages.return_value = [mock.MagicMock(), mock.MagicMock()]

        fetch_and_process_messages(queue_name, queue, num_messages,
                                   visibility_timeout)

        mock_get_messages.assert_called_once_with(
            queue, num_messages, visibility_timeout=visibility_timeout)
        mock_message_handler.assert_has_calls(
            [mock.call(x) for x in mock_get_messages.return_value])
        for message in mock_get_messages.return_value:
            message.delete.assert_called_once_with()
Ejemplo n.º 6
0
    def test_post_process_hook_exception_raised(self, mock_message_handler,
                                                mock_get_messages, settings):
        queue_name = 'my-queue'
        queue = mock.MagicMock()
        settings.HEDWIG_POST_PROCESS_HOOK = 'tests.test_consumer.post_process_hook'

        mock_message = mock.MagicMock()
        mock_get_messages.return_value = [mock_message]

        post_process_hook.reset_mock()
        post_process_hook.side_effect = RuntimeError('fail')

        fetch_and_process_messages(queue_name, queue)

        post_process_hook.assert_called_once_with(
            sqs_queue_message=mock_message)
        mock_message.delete.assert_not_called()