48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""测试所有API端点"""
|
|
|
|
import requests
|
|
|
|
def test_apis():
|
|
"""测试API端点"""
|
|
base_url = "http://localhost:8001/api/v1"
|
|
|
|
# 测试算法列表(不需要认证)
|
|
print("1. 测试算法列表(不需要认证):")
|
|
try:
|
|
response = requests.get(f"{base_url}/algorithms/")
|
|
print(f" 状态码: {response.status_code}")
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print(f" 成功获取 {len(data.get('algorithms', []))} 个算法")
|
|
else:
|
|
print(f" 失败: {response.text}")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
# 测试用户信息(需要认证)
|
|
print("\n2. 测试用户信息(需要认证):")
|
|
try:
|
|
response = requests.get(f"{base_url}/users/me")
|
|
print(f" 状态码: {response.status_code}")
|
|
if response.status_code == 401:
|
|
print(f" 需要认证(正常)")
|
|
else:
|
|
print(f" 响应: {response.text}")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
# 测试服务列表(需要认证)
|
|
print("\n3. 测试服务列表(需要认证):")
|
|
try:
|
|
response = requests.get(f"{base_url}/services")
|
|
print(f" 状态码: {response.status_code}")
|
|
if response.status_code == 401:
|
|
print(f" 需要认证(正常)")
|
|
else:
|
|
print(f" 响应: {response.text[:200]}")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_apis() |