def test_cunsume_empty_queue(self):
        queue = MagicMock()
        queue.receive_messages = MagicMock(return_value=[])

        consumer = SQSConsumerPool(max_threads=1, processor_class=SQSMessagesProcessor, queue_name=self.queue_name)

        with patch.object(SQSMessagesProcessor, 'processor_class', create=True) as mock_processor_class:
            consumer.consume(queue)

        assert mock_processor_class.called
    def test_cunsume(self):
        message = MagicMock()
        queue = MagicMock()
        queue.receive_messages = MagicMock(return_value=[message])

        consumer = SQSConsumerPool(max_threads=1, processor_class=SQSMessagesProcessor, queue_name=self.queue_name)

        with patch.object(SQSMessagesProcessor, 'processor_class', create=True) as mock_processor_class:
            consumer.consume(queue)

        mock_processor_class.assert_has_calls([
            call(),
            call().process(message)])
 def test_init(self):
     max_threads = MagicMock()
     processor_class = MagicMock()
     queue_name = MagicMock()
     consumer = SQSConsumerPool(max_threads=max_threads, processor_class=processor_class, queue_name=queue_name)
     assert consumer.max_threads == max_threads
     assert consumer.queue_name == queue_name
     assert consumer.processor_class == processor_class
    def test_cunsume_message(self):
        message = MagicMock()
        message.body = '{"Records":[{"s3":{"bucket":{"name":"name"},"object":{"key":"key"}}}]}'
        queue = MagicMock()
        queue.receive_messages = MagicMock(return_value=[message])

        class _SQSMessagesProcessor(SQSMessagesProcessor):
            def __init__(self):
                self.processor_class = SQSMessageProcessor

        consumer = SQSConsumerPool(max_threads=1, processor_class=_SQSMessagesProcessor, queue_name=self.queue_name)

        with patch.object(SQSMessageProcessor, 'processor_class', create=True) as mock_processor_class:
            consumer.consume(queue)

        mock_processor_class.assert_has_calls([
            call(),
            call().process({'Records': [{'s3': {'bucket': {'name': 'name'}, 'object': {'key': 'key'}}}]})])