"""Lambda test module.""" from unittest.mock import patch from content_utils.exceptions import IneligibleEventError from content_utils.exceptions import InvalidProductException import pytest from src.exceptions import AudioDurationException @patch('src.app.filter_ineligible_product') def test_app(mock_filter, mock_event): """Test app.""" from src.app import handler mock_filter.side_effect = [ AudioDurationException('foo'), InvalidProductException('bar'), IneligibleEventError('zar'), AssertionError('baz'), None, AssertionError('qux') ] actual = handler(mock_event, None) assert actual == {'is_eligible': False, 'reason': 'foo'} actual = handler(mock_event, None) assert actual == {'is_eligible': False, 'reason': 'bar'} actual = handler(mock_event, None) assert actual == {'is_eligible': False, 'reason': 'zar'} with pytest.raises(AssertionError) as e: handler(mock_event, None) assert 'baz' in str(e) actual = handler(mock_event, None) assert actual == {'is_eligible': True, 'reason': ''} actual = handler({'bypass_filter': True}, None) assert actual == {'is_eligible': True, 'reason': ''} with pytest.raises(AssertionError) as e: handler({'bypass_filter': False, **mock_event}, None) assert 'qux' in str(e)