forked from alshurov13/allure-testops-mcp-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp.py
More file actions
executable file
·222 lines (175 loc) · 6.33 KB
/
test_mcp.py
File metadata and controls
executable file
·222 lines (175 loc) · 6.33 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python3
"""
Test script for Allure TestOps MCP Server
"""
import os
import sys
import asyncio
import json
from typing import Any, Dict
# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from allure_client import AllureClient, create_allure_client
from controllers.test_case_controller import (
test_case_controller_tools,
handle_test_case_controller_tool
)
from controllers.launch_controller import (
launch_controller_tools,
handle_launch_controller_tool
)
from controllers.project_controller import (
project_controller_tools,
handle_project_controller_tool
)
async def test_allure_client():
"""Test AllureClient connection"""
print("Testing AllureClient...")
allure_url = os.environ.get('ALLURE_TESTOPS_URL')
allure_token = os.environ.get('ALLURE_TOKEN')
if not allure_url or not allure_token:
print("ERROR: ALLURE_TESTOPS_URL and ALLURE_TOKEN must be set")
return False
try:
client = create_allure_client(allure_url, allure_token)
# Test simple GET request
print(f" Connecting to: {allure_url}")
print(f" Token: {allure_token[:10]}...")
# Try to get projects list
try:
result = await client.get('/api/project', {'page': 0, 'size': 1})
print(f" ✓ Successfully connected to Allure TestOps")
print(f" ✓ API is accessible")
return True
except Exception as e:
print(f" ✗ API request failed: {e}")
return False
except Exception as e:
print(f" ✗ Client creation failed: {e}")
return False
async def test_controller_tools():
"""Test controller tools registration"""
print("\nTesting controller tools...")
controllers = [
("test_case", test_case_controller_tools),
("launch", launch_controller_tools),
("project", project_controller_tools),
]
total_tools = 0
for name, tools in controllers:
count = len(tools) if tools else 0
total_tools += count
status = "✓" if count > 0 else "✗"
print(f" {status} {name}: {count} tools")
print(f" Total tools: {total_tools}")
return total_tools > 0
async def test_tool_handler():
"""Test tool handler execution"""
print("\nTesting tool handler...")
allure_url = os.environ.get('ALLURE_TESTOPS_URL')
allure_token = os.environ.get('ALLURE_TOKEN')
project_id = os.environ.get('PROJECT_ID', '1')
if not allure_url or not allure_token:
print(" ✗ Environment variables not set")
return False
try:
client = create_allure_client(allure_url, allure_token)
# Test a simple tool call (list projects)
print(" Testing 'allure_findAll_22' (list projects)...")
args = {
'page': 0,
'size': 1
}
result = await handle_project_controller_tool(
client,
'allure_findAll_22',
args,
project_id
)
print(f" ✓ Tool handler executed successfully")
print(f" ✓ Result length: {len(result)} characters")
# Try to parse JSON
try:
data = json.loads(result)
print(f" ✓ Result is valid JSON")
return True
except json.JSONDecodeError:
print(f" ✗ Result is not valid JSON")
return False
except Exception as e:
print(f" ✗ Tool handler failed: {e}")
import traceback
traceback.print_exc()
return False
async def test_mcp_server_structure():
"""Test MCP server structure"""
print("\nTesting MCP server structure...")
try:
# Try to import index
from index import server, all_tools, tool_handler_map
print(f" ✓ Server created: {server}")
print(f" ✓ Total tools registered: {len(all_tools)}")
print(f" ✓ Tool handlers mapped: {len(tool_handler_map)}")
# Check if tools have required structure
if all_tools:
sample_tool = all_tools[0]
required_fields = ['name', 'description', 'inputSchema']
missing = [f for f in required_fields if f not in sample_tool]
if missing:
print(f" ✗ Tools missing fields: {missing}")
return False
else:
print(f" ✓ Tools have required structure")
return True
except ImportError as e:
print(f" ✗ Failed to import index: {e}")
return False
except Exception as e:
print(f" ✗ Structure test failed: {e}")
import traceback
traceback.print_exc()
return False
async def main():
"""Run all tests"""
print("=" * 60)
print("Allure TestOps MCP Server - Test Suite")
print("=" * 60)
results = []
# Test 1: AllureClient
results.append(await test_allure_client())
# Test 2: Controller tools
results.append(await test_controller_tools())
# Test 3: Tool handler
if results[0]: # Only test if client works
results.append(await test_tool_handler())
else:
print("\nSkipping tool handler test (client not working)")
results.append(False)
# Test 4: MCP server structure
results.append(await test_mcp_server_structure())
# Summary
print("\n" + "=" * 60)
print("Test Summary")
print("=" * 60)
test_names = [
"AllureClient connection",
"Controller tools registration",
"Tool handler execution",
"MCP server structure"
]
for i, (name, result) in enumerate(zip(test_names, results)):
status = "PASS" if result else "FAIL"
symbol = "✓" if result else "✗"
print(f" {symbol} {name}: {status}")
passed = sum(results)
total = len(results)
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\n✓ All tests passed! MCP server is ready to use.")
return 0
else:
print(f"\n✗ {total - passed} test(s) failed. Please check the errors above.")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)