Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script for the POA Graph Web Interface Server | |
| """ | |
| import requests | |
| import json | |
| BASE_URL = "http://localhost:8080" | |
| def test_datasets(): | |
| """Test the datasets endpoint""" | |
| print("Testing /api/datasets...") | |
| try: | |
| response = requests.get(f"{BASE_URL}/api/datasets") | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"β Success! Found {len(data['datasets'])} datasets:") | |
| for dataset in data['datasets']: | |
| print(f" - {dataset['display_name']}: {dataset['count']} graphs") | |
| else: | |
| print(f"β Error: {response.status_code}") | |
| except Exception as e: | |
| print(f"β Exception: {e}") | |
| def test_entities(): | |
| """Test the entities endpoint""" | |
| print("\nTesting /api/entities?dataset=bio...") | |
| try: | |
| response = requests.get(f"{BASE_URL}/api/entities?dataset=bio") | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"β Success! Found {len(data['entities'])} entities in bio dataset") | |
| if data['entities']: | |
| print(f" Sample entity: {data['entities'][0]['entity']} ({data['entities'][0]['model']})") | |
| else: | |
| print(f"β Error: {response.status_code}") | |
| except Exception as e: | |
| print(f"β Exception: {e}") | |
| def test_load_graph(): | |
| """Test loading a specific graph""" | |
| print("\nTesting /api/load_existing_graph...") | |
| try: | |
| # First get entities to find a valid filepath | |
| response = requests.get(f"{BASE_URL}/api/entities?dataset=bio") | |
| if response.status_code == 200: | |
| data = response.json() | |
| if data['entities']: | |
| filepath = data['entities'][0]['filepath'] | |
| print(f" Loading graph: {filepath}") | |
| # Test loading the graph | |
| response = requests.post( | |
| f"{BASE_URL}/api/load_existing_graph", | |
| json={"filepath": filepath} | |
| ) | |
| if response.status_code == 200: | |
| graph_data = response.json() | |
| if graph_data['success']: | |
| print(f"β Success! Loaded graph with {graph_data['num_nodes']} nodes and {graph_data['num_edges']} edges") | |
| print(f" Entity: {graph_data['metadata']['entity']}") | |
| print(f" Model: {graph_data['metadata']['model']}") | |
| else: | |
| print(f"β Error: {graph_data['error']}") | |
| else: | |
| print(f"β Error: {response.status_code}") | |
| else: | |
| print("β No entities found to test with") | |
| else: | |
| print(f"β Error getting entities: {response.status_code}") | |
| except Exception as e: | |
| print(f"β Exception: {e}") | |
| if __name__ == "__main__": | |
| print("Testing POA Graph Web Interface Server...") | |
| print("Make sure the server is running on http://localhost:8080") | |
| print("=" * 50) | |
| test_datasets() | |
| test_entities() | |
| test_load_graph() | |
| print("\n" + "=" * 50) | |
| print("Test completed!") | |