#!/usr/bin/env python3 """ Test script to verify API key enforcement without environment variables """ import os import sys # Remove any existing API key environment variable if 'A1D_API_KEY' in os.environ: del os.environ['A1D_API_KEY'] # Import after removing environment variable from app import remove_bg_wrapper def test_no_api_key(): """Test that API key is required when not provided""" try: result = remove_bg_wrapper("https://example.com/test.jpg") print(f"โŒ FAILED: Function should have failed but returned: {result}") return False except Exception as e: print(f"โœ… SUCCESS: Function correctly failed with error: {str(e)}") return True if __name__ == "__main__": print("๐Ÿงช Testing API key enforcement...") print("=" * 50) # Check environment print(f"A1D_API_KEY in environment: {'A1D_API_KEY' in os.environ}") print(f"SPACE_ID in environment: {'SPACE_ID' in os.environ}") # Run test success = test_no_api_key() print("=" * 50) if success: print("โœ… Test PASSED: API key enforcement is working") sys.exit(0) else: print("โŒ Test FAILED: API key enforcement is NOT working") sys.exit(1)