"""Lambda test module.""" from unittest.mock import patch import pytest from requests import HTTPError from src import app SPOTIFY_ID = '3Nrfpe0tUJi4K4DXYWgMUX' @patch('src.app.graphql_gateway') def test_handler_success(mock_graphql, mock_event_spotify, mock_global_participant_data): """Test handler function.""" mock_graphql.get_global_participant_data.return_value = \ mock_global_participant_data result = app.handler(mock_event_spotify, {}) assert result == mock_global_participant_data mock_graphql.get_global_participant_data.assert_called_with(mock_event_spotify) @patch('src.app.graphql_gateway') def test_handler_retry(mock_graphql, mock_event_spotify): """Test handler function retry.""" mock_graphql.get_global_participant_data.side_effect = HTTPError() with pytest.raises(app.RetryException): app.handler(mock_event_spotify, {}) @patch('src.app.graphql_gateway') def test_handler_failure(mock_graphql, mock_event_spotify): """Test handler function fails.""" mock_graphql.get_global_participant_data.side_effect = OSError() with pytest.raises(app.FatalException): app.handler(mock_event_spotify, {})