Exemplo n.º 1
0
 def test_success(self, mock_load_and_validate_message, mock_call_task,
                  message_data, message):
     mock_load_and_validate_message.return_value = message
     receipt = str(uuid.uuid4())
     message_handler(json.dumps(message_data), receipt)
     mock_load_and_validate_message.assert_called_once_with(message_data)
     mock_call_task.assert_called_once_with(message, receipt)
    def test_special_handling_ignore_exception(self, mock_call_task, message_data, message):
        mock_call_task.side_effect = IgnoreException
        # no exception raised
        with mock.patch.object(consumer.logger, 'info') as logging_mock:
            message_handler(json.dumps(message_data), None)

            logging_mock.assert_called_once()
    def test_special_handling_retry_error(self, mock_call_task, message_data, message):

        mock_call_task.side_effect = RetryException
        with pytest.raises(mock_call_task.side_effect), mock.patch.object(consumer.logger, 'info') as logging_mock:
            message_handler(json.dumps(message_data), None)

            logging_mock.assert_called_once()
Exemplo n.º 4
0
 def test_fails_on_validation_error(self, mock_load_and_validate_message,
                                    mock_call_task, message_data):
     error_message = 'Invalid message body'
     mock_load_and_validate_message.side_effect = ValidationError(
         error_message)
     with pytest.raises(ValidationError):
         message_handler(json.dumps(message_data), None)
     mock_call_task.assert_not_called()
Exemplo n.º 5
0
 def test_fails_on_task_failure(self, mock_load_and_validate_message,
                                mock_call_task, message_data, message):
     mock_load_and_validate_message.return_value = message
     mock_call_task.side_effect = Exception
     with pytest.raises(mock_call_task.side_effect):
         message_handler(json.dumps(message_data), None)
Exemplo n.º 6
0
 def test_fails_on_invalid_json(self, *mocks):
     with pytest.raises(ValueError):
         message_handler("bad json", None)
    def test_special_handling_logging_error(self, mock_call_task, message_data, message):
        mock_call_task.side_effect = LoggingException('foo', extra={'mickey': 'mouse'})
        with pytest.raises(LoggingException), mock.patch.object(consumer.logger, 'exception') as logging_mock:
            message_handler(json.dumps(message_data), None)

            logging_mock.assert_called_once_with('foo', extra={'mickey': 'mouse'})
 def test_fails_on_task_failure(self, mock_call_task, message_data, message):
     mock_call_task.side_effect = Exception
     with pytest.raises(mock_call_task.side_effect):
         message_handler(json.dumps(message_data), None)
 def test_success(self, mock_call_task, message_data, message):
     receipt = str(uuid.uuid4())
     message_handler(json.dumps(message_data), receipt)
     mock_call_task.assert_called_once_with(message, receipt)