"""Lambda test module.""" from unittest.mock import MagicMock from unittest.mock import patch from src import app import config # Mock the environment and template to avoid file system dependency @patch('src.app.Environment') def test_handler(mock_env): """Test handler function.""" # Set up the mock objects and their return values mock_loader = MagicMock() mock_env.return_value = MagicMock(loader=mock_loader) mock_template = MagicMock() mock_env().get_template.return_value = mock_template mock_template.render.return_value = 'Rendered Content' fake_event = {} fake_context = {} response = app.handler(fake_event, fake_context) # Check that the response is what you expect assert response['statusCode'] == 200 assert response['statusDescription'] == '200 OK' assert response['isBase64Encoded'] is False assert response['headers']['Content-Type'] == 'text/html' assert response['body'] == 'Rendered Content' # Ensure the template was called with the expected context mock_env().get_template.assert_called_once_with('index-template.html.j2') mock_template.render.assert_called_once_with(accounts=config.AWS_ACCOUNTS_MAPPING) # noqa: E501