File size: 4,310 Bytes
8eab354 |
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
"""
Test script for InklyAI Web UI
"""
import requests
import json
import os
import time
from pathlib import Path
def test_web_ui():
"""Test the web UI functionality."""
print("π§ͺ Testing InklyAI Web UI")
print("=" * 50)
base_url = "http://localhost:8080"
# Test 1: Health check
print("\n1. Testing health check...")
try:
response = requests.get(f"{base_url}/api/health")
health = response.json()
print(f" β
Health status: {health['status']}")
print(f" β
Agents registered: {health['agents_registered']}")
except Exception as e:
print(f" β Health check failed: {e}")
return False
# Test 2: Get agents
print("\n2. Testing agent listing...")
try:
response = requests.get(f"{base_url}/api/agents")
agents = response.json()
print(f" β
Found {agents['total_agents']} agents")
for agent in agents['agents']:
print(f" - {agent['agent_id']} ({'Active' if agent['is_active'] else 'Inactive'})")
except Exception as e:
print(f" β Agent listing failed: {e}")
# Test 3: Test signature verification (if sample data exists)
print("\n3. Testing signature verification...")
if os.path.exists('data/samples/john_doe_1.png') and os.path.exists('data/samples/john_doe_2.png'):
try:
# Test with sample signatures
with open('data/samples/john_doe_1.png', 'rb') as f1, open('data/samples/john_doe_2.png', 'rb') as f2:
files = {
'signature1': ('john_doe_1.png', f1, 'image/png'),
'signature2': ('john_doe_2.png', f2, 'image/png')
}
data = {'agent_id': 'Agent_01'}
response = requests.post(f"{base_url}/api/verify", files=files, data=data)
result = response.json()
if result['success']:
print(f" β
Verification successful")
print(f" β
Similarity: {result['similarity_score']:.3f}")
print(f" β
Verified: {result['is_verified']}")
else:
print(f" β Verification failed: {result['error']}")
except Exception as e:
print(f" β Signature verification failed: {e}")
else:
print(" β οΈ Sample data not found. Run demo.py first to create sample signatures.")
# Test 4: Test agent stats
print("\n4. Testing agent statistics...")
try:
response = requests.get(f"{base_url}/api/stats")
stats = response.json()
if stats['success']:
print(f" β
Statistics loaded successfully")
for agent_id, agent_stats in stats['stats'].items():
print(f" - {agent_id}: {agent_stats['total_verifications']} verifications, "
f"success rate: {agent_stats['success_rate']:.1%}")
else:
print(f" β Stats failed: {stats['error']}")
except Exception as e:
print(f" β Agent stats failed: {e}")
print("\nπ Web UI tests completed!")
print(f"\nπ Access the web UI at: {base_url}")
print(f"π Agent management at: {base_url}/agents")
return True
def check_web_server():
"""Check if the web server is running."""
try:
response = requests.get("http://localhost:8080/api/health", timeout=5)
return response.status_code == 200
except:
return False
if __name__ == "__main__":
print("InklyAI Web UI Test Suite")
print("=" * 50)
# Check if web server is running
if not check_web_server():
print("β Web server is not running!")
print("Please start the web server with:")
print(" python web_app.py")
print("\nThen run this test script again.")
exit(1)
print("β
Web server is running")
# Run tests
test_web_ui()
print("\n" + "=" * 50)
print("Web UI Test Summary:")
print("β
Health monitoring")
print("β
Agent management")
print("β
Signature verification")
print("β
Statistics and reporting")
print("β
Error handling")
print("\nπ Web UI is ready for use!")
|