"""Lambda integration test.""" import pytest import os from src.app import handler TEST_SCRIPT_BASE_DIR = 'tests/integration/scripts' @pytest.fixture def test_event(): """Simulate an AWS Lambda event input.""" return {'db_name': 'test-sql'} def test_lambda_handler(test_event, monkeypatch): """Test Lambda execution using the handler function.""" monkeypatch.setattr('config.SCRIPT_BASE_DIR', TEST_SCRIPT_BASE_DIR) db_name = test_event['db_name'] scripts_dir = os.path.join(TEST_SCRIPT_BASE_DIR, db_name) # Ensure the test directory contains SQL scripts sql_files = [f for f in os.listdir(scripts_dir) if f.endswith('.sql')] assert sql_files, 'No SQL scripts found in the integration folder!' # Call the Lambda function response = handler(test_event, None) # Check that scripts were executed assert response['scripts_run'] == len(sql_files), 'Not all scripts run' print(f'Executed {response["scripts_run"]} scripts successfully!')