Spaces:
Running
Running
File size: 1,249 Bytes
37495c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#!/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)
|