Singularity / scripts /dev /2_test_graph_operation.py
SlappAI's picture
dev scripts
64ed965
raw
history blame
2.56 kB
# scripts/test_graph_operations.py
import requests
BASE_URL = "http://localhost:5000"
def test_load_graph():
print("\n--- Testing Graph Loading ---")
response = requests.post(f"{BASE_URL}/load_graph")
print("Load Graph Response:", response.json())
def test_create_node():
print("\n--- Testing Node Creation ---")
data = {
"node_id": "patient_123",
"data": {
"name": "John Doe",
"age": 45,
"medical_conditions": ["hypertension", "diabetes"]
},
"domain": "Healthcare",
"type": "Patient"
}
response = requests.post(f"{BASE_URL}/create_node", json=data)
print("Create Node Response:", response.json())
def test_query_node(node_id):
print(f"\n--- Testing Node Query ({node_id}) ---")
response = requests.get(f"{BASE_URL}/query_node", params={"node_id": node_id})
print(f"Query Node {node_id} Response:", response.json())
def test_list_nodes():
print("\n--- Testing List All Nodes ---")
response = requests.get(f"{BASE_URL}/list_nodes")
print("List Nodes Response:", response.json())
def test_list_relationships():
print("\n--- Testing List All Relationships ---")
response = requests.get(f"{BASE_URL}/list_relationships")
print("List Relationships Response:", response.json())
def test_traverse_node(node_id, direction):
print(f"\n--- Testing Node Traversal ({node_id}, {direction}) ---")
response = requests.get(f"{BASE_URL}/traverse_node", params={"node_id": node_id, "direction": direction})
print(f"Traversal Path ({node_id} - {direction}):", response.json())
def test_inspect_relationships(node_id):
print(f"\n--- Testing Inspect Relationships for Node ({node_id}) ---")
response = requests.get(f"{BASE_URL}/inspect_relationships", params={"node_id": node_id})
print(f"Inspect Relationships for {node_id}:", response.json())
if __name__ == "__main__":
# Step 1: Load the Graph
test_load_graph()
# Step 2: Create a sample node
test_create_node()
# Step 3: Query specific nodes
test_query_node("patient_123")
test_query_node("Healthcare")
# Step 4: List all nodes
test_list_nodes()
# Step 5: List all relationships
test_list_relationships()
# Step 6: Traverse nodes (both up and down)
test_traverse_node("patient_123", "up")
test_traverse_node("Healthcare", "down")
# Step 7: Inspect relationships, including hierarchy traversal
test_inspect_relationships("Healthcare")
test_inspect_relationships("patient_123")