"""Lambda test module.""" from unittest.mock import patch import pytest from requests import HTTPError from src.spotify_parser import ParsingError from src import app SPOTIFY_ID = '6oO3QiWdVj5FZQwbdRtsRh' @patch('src.app.spotify_parser') def test_handler(spotify_mock, mock_event): """Test handler successful execution.""" spotify_mock.get_spotify_monthly_listeners.return_value = 100 result = app.handler(mock_event, {}) spotify_mock.get_spotify_monthly_listeners.assert_called_with(SPOTIFY_ID) assert result == {'spotify_monthly_listeners': 100} @pytest.mark.parametrize( 'error,raised_error', [ (ParsingError(), app.RetryException()), (HTTPError(), app.RetryException()), (OSError(), app.FatalException()) ]) def test_handler_failure(mock_event, error, raised_error): """Test handler successful execution.""" with patch('src.app.spotify_parser') as spotify_mock: spotify_mock.get_spotify_monthly_listeners.side_effect = error with pytest.raises(type(raised_error)): app.handler(mock_event, {})