"""Lambda test module.""" from unittest.mock import patch import pytest from src import app as index valid_events = [ ('episodes-gone-live', '/job/episode-gone-live'), ('episode-going-live-tomorrow', '/job/episode-going-live-tomorrow'), ('ad-past-due', '/job/ad-past-due'), ('ad-due-tomorrow', '/job/ad-due-tomorrow') ] @patch('owsrequest.request.process') @pytest.mark.parametrize('even_type,expected_endpoint', valid_events) def test_notification_success(process, even_type, expected_endpoint): """Test handler function with a valid event.""" process.return_value.status_code = 200 index.handler({'eventType': even_type}, None) process.assert_called_with( application='lambda-podcast-notifications', environment='test', method='GET', service_name='ows-podcast', path=expected_endpoint, ) @patch('owsrequest.request.process') @patch('sentry_sdk.capture_message') def test_notification_no_event_type(sentry, process): """Test handler function with missing event type.""" index.handler({}, None) process.assert_not_called() sentry.assert_called_with('Event does not have event type {}') @patch('owsrequest.request.process') @patch('sentry_sdk.capture_message') def test_notification_unmapped_event(sentry, process): """Test handler function with unmapped event type.""" index.handler({'eventType': 'nothing-good'}, None) process.assert_not_called() sentry.assert_called_with('eventType does not map to an endpoint {\'eventType\': \'nothing-good\'}') # noqa