"""Tests for lambda exceptions module.""" from unittest.mock import patch import pytest from constants import errors from src import lambda_exceptions @patch('src.lambda_exceptions.status') @pytest.mark.parametrize('error_code,error_params,expected_message', [ ('Some', None, 'Unknown Error'), ( errors.S3_FILE_NOT_FOUND_CODE, {'key': 'k', 'bucket': 'b'}, 'k not found in bucket b!') ]) def test_notify_and_raise( status_mock, error_code, error_params, expected_message): """Test notifying and raising Exception.""" test_function = 'function' test_status = 'status' test_filename = 'filename' test_bucket = 'bucket' test_input_params = {'foo': 'bar'} with pytest.raises(Exception) as ex: lambda_exceptions.notify_and_raise( test_function, test_status, error_code, test_filename, test_bucket, error_params, test_input_params) status_mock.send_general_status.assert_called_with( function=test_function, status=test_status, filename=test_filename, error_code=error_code, description=expected_message, bucket=test_bucket, input_params=test_input_params, ) assert str(ex.value) == expected_message