-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
95 lines (71 loc) · 2.54 KB
/
test_server.py
File metadata and controls
95 lines (71 loc) · 2.54 KB
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
#!/usr/bin/env python3
"""
Test script for MCP GeoNode Server
This script demonstrates how to use the MCP server for common GeoNode operations.
"""
import asyncio
import json
from mcp_geonode.server import mcp, configure_geonode
async def test_configuration():
"""Test GeoNode configuration."""
print("Testing GeoNode configuration...")
# Configure with public demo instance
result = configure_geonode("https://master.demo.geonode.org")
print(f"Configuration result: {result}")
return "Successfully configured" in result
async def test_list_resources():
"""Test listing resources."""
print("\nTesting resource listing...")
try:
# Get list_resources tool function directly from the server
tools = await mcp.list_tools()
list_resources_tool = None
for tool in tools:
if tool.name == "list_resources":
list_resources_tool = tool
break
if list_resources_tool:
print("Found list_resources tool")
# Note: In a real test, you would call the tool through the MCP protocol
print("Tool description:", list_resources_tool.description)
return True
else:
print("list_resources tool not found")
return False
except Exception as e:
print(f"Error testing resource listing: {e}")
return False
async def main():
"""Run all tests."""
print("MCP GeoNode Server Test Suite")
print("=" * 40)
tests = [
("Configuration", test_configuration),
("List Resources", test_list_resources),
]
results = []
for test_name, test_func in tests:
try:
result = await test_func()
results.append((test_name, result))
status = "PASS" if result else "FAIL"
print(f"{test_name}: {status}")
except Exception as e:
results.append((test_name, False))
print(f"{test_name}: FAIL - {e}")
print("\n" + "=" * 40)
print("Test Summary:")
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "✓" if result else "✗"
print(f" {status} {test_name}")
print(f"\nPassed: {passed}/{total}")
if passed == total:
print("All tests passed! 🎉")
return 0
else:
print("Some tests failed. 😞")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())