Spaces:
Running
Running
| #!/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) | |