File size: 3,210 Bytes
102ae18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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!")