You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.4 KiB
81 lines
2.4 KiB
#!/usr/bin/env python
|
|
import urllib.request
|
|
import json
|
|
|
|
# 获取 API Key
|
|
with open('config.json') as f:
|
|
cfg = json.load(f)
|
|
api_key = cfg['server']['api_key']
|
|
|
|
print("=" * 50)
|
|
print("Testing API Test List")
|
|
print("=" * 50)
|
|
|
|
# 测试获取 API 测试列表
|
|
try:
|
|
req = urllib.request.Request(
|
|
'http://localhost:8080/v1/admin/tests/api',
|
|
headers={'X-Admin-Token': api_key}
|
|
)
|
|
response = urllib.request.urlopen(req)
|
|
data = json.loads(response.read().decode())
|
|
print(f"✓ API Test List: {len(data['data']['categories'])} categories")
|
|
for cat in data['data']['categories']:
|
|
print(f" - {cat['name']}: {len(cat['items'])} items")
|
|
for item in cat['items'][:2]:
|
|
print(f" - [{item['method']}] {item['name']}")
|
|
if len(cat['items']) > 2:
|
|
print(f" ... and {len(cat['items'])-2} more")
|
|
except Exception as e:
|
|
print(f"✗ Error: {e}")
|
|
|
|
print("\n" + "=" * 50)
|
|
print("Testing WebSocket Test List")
|
|
print("=" * 50)
|
|
|
|
# 测试获取 WebSocket 测试列表
|
|
try:
|
|
req = urllib.request.Request(
|
|
'http://localhost:8080/v1/admin/tests/ws',
|
|
headers={'X-Admin-Token': api_key}
|
|
)
|
|
response = urllib.request.urlopen(req)
|
|
data = json.loads(response.read().decode())
|
|
print(f"✓ WS Test List: {len(data['data']['cases'])} cases")
|
|
for case in data['data']['cases'][:5]:
|
|
print(f" - {case['name']}: {case['action']} {case.get('symbols', [])}")
|
|
except Exception as e:
|
|
print(f"✗ Error: {e}")
|
|
|
|
print("\n" + "=" * 50)
|
|
print("Testing Run API Test (health check)")
|
|
print("=" * 50)
|
|
|
|
# 测试执行单个 API 测试
|
|
try:
|
|
req = urllib.request.Request(
|
|
'http://localhost:8080/v1/admin/tests/api/run',
|
|
data=json.dumps({'id': 'admin_health'}).encode('utf-8'),
|
|
headers={
|
|
'Content-Type': 'application/json',
|
|
'X-Admin-Token': api_key
|
|
},
|
|
method='POST'
|
|
)
|
|
response = urllib.request.urlopen(req)
|
|
data = json.loads(response.read().decode())
|
|
if data['code'] == 0:
|
|
result = data['data']
|
|
print(f"✓ Test Result: {'PASS' if result['success'] else 'FAIL'}")
|
|
print(f" - Latency: {result['latency']}ms")
|
|
print(f" - Status: {result['status_code']}")
|
|
print(f" - URL: {result['request']['url']}")
|
|
else:
|
|
print(f"✗ Error: {data['message']}")
|
|
except Exception as e:
|
|
print(f"✗ Error: {e}")
|
|
|
|
print("\n" + "=" * 50)
|
|
print("All tests completed!")
|
|
print("=" * 50)
|