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()
    def test_post_process_hook(self, mock_message_handler, mock_get_messages, settings):
        queue_name = 'my-queue'
        queue = mock.MagicMock()
        settings.TASKHAWK_POST_PROCESS_HOOK = 'tests.test_consumer.post_process_hook'

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

        fetch_and_process_messages(queue_name, queue)

        post_process_hook.assert_has_calls(
            [mock.call(queue_name=queue_name, sqs_queue_message=x) for x in mock_get_messages.return_value]
        )
    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()
Exemplo 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()
    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()
    def test_post_process_hook_exception_raised(self, mock_message_handler, mock_get_messages, settings):
        queue_name = 'my-queue'
        queue = mock.MagicMock()
        settings.TASKHAWK_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(queue_name=queue_name, sqs_queue_message=mock_message)
        mock_message.delete.assert_not_called()