""" 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!")