File size: 3,247 Bytes
f4bee9e | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | ο»Ώ"""
π§ͺ ENTERPRISE PLATFORM - QUICK TEST
Quick test to verify everything works.
"""
import requests
import time
import sys
def test_platform():
"""Test the enterprise platform"""
print("\n" + "="*80)
print("π§ͺ ENTERPRISE PLATFORM QUICK TEST")
print("="*80)
base_url = "http://localhost:8000"
print(f"\nTesting platform at: {base_url}")
print("Make sure platform is running first!")
print("Run: python enterprise_platform.py")
print()
try:
# Test 1: Root endpoint
print("1. Testing root endpoint...")
response = requests.get(base_url, timeout=3)
if response.status_code == 200:
data = response.json()
print(f" β
Service: {data.get('service')}")
print(f" β
Version: {data.get('version')}")
print(f" β
Status: {data.get('status')}")
else:
print(f" β Failed: HTTP {response.status_code}")
return False
# Test 2: Health endpoint
print("\n2. Testing health endpoint...")
response = requests.get(f"{base_url}/health", timeout=3)
if response.status_code == 200:
data = response.json()
print(f" β
Status: {data.get('status')}")
print(f" β
PyTorch: {data.get('components', {}).get('pytorch')}")
else:
print(f" β Failed: HTTP {response.status_code}")
return False
# Test 3: Try a prediction
print("\n3. Testing prediction endpoint...")
test_data = {
"data": {
"input": [0.0] * 784 # Blank 28x28 image
}
}
response = requests.post(
f"{base_url}/predict",
json=test_data,
timeout=5
)
if response.status_code == 200:
data = response.json()
print(f" β
Prediction made")
print(f" β
Status: {data.get('status')}")
print(f" β
Prediction: {data.get('prediction')}")
print(f" β
Confidence: {data.get('confidence', 0):.2%}")
else:
print(f" β οΈ Prediction returned: HTTP {response.status_code}")
if response.text:
print(f" Response: {response.text[:100]}...")
print("\n" + "="*80)
print("π ALL TESTS PASSED!")
print("\nπ Access your platform at:")
print(f" Main: {base_url}")
print(f" Docs: {base_url}/docs")
print(f" Health: {base_url}/health")
return True
except requests.exceptions.ConnectionError:
print("\nβ Cannot connect to server!")
print(" Make sure the platform is running:")
print(" python enterprise_platform.py")
return False
except Exception as e:
print(f"\nβ Test failed: {e}")
return False
if __name__ == "__main__":
print("\nEnterprise Adversarial ML Security Platform - Quick Test")
print("Version: 4.0.0")
try:
success = test_platform()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\nTest cancelled.")
sys.exit(1)
|