67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
![]() |
#!/usr/bin/env python3
|
|||
|
"""
|
|||
|
简化的API测试 - 只测试基本的GET请求
|
|||
|
"""
|
|||
|
|
|||
|
import requests
|
|||
|
import json
|
|||
|
|
|||
|
BASE_URL = "http://localhost:5000"
|
|||
|
|
|||
|
def test_get_api(url, description):
|
|||
|
"""测试GET API"""
|
|||
|
try:
|
|||
|
print(f"📝 {description}")
|
|||
|
print(f"GET {url}")
|
|||
|
|
|||
|
response = requests.get(url, timeout=10)
|
|||
|
print(f"状态码: {response.status_code}")
|
|||
|
|
|||
|
if response.status_code == 200:
|
|||
|
data = response.json()
|
|||
|
print(f"✅ 成功: {data.get('status', 'unknown')}")
|
|||
|
if 'data' in data:
|
|||
|
if isinstance(data['data'], list):
|
|||
|
print(f" 数据条数: {len(data['data'])}")
|
|||
|
elif isinstance(data['data'], dict):
|
|||
|
print(f" 数据字段: {list(data['data'].keys())}")
|
|||
|
else:
|
|||
|
print(f"❌ 失败: {response.text}")
|
|||
|
|
|||
|
print("-" * 60)
|
|||
|
return response.status_code == 200
|
|||
|
|
|||
|
except Exception as e:
|
|||
|
print(f"❌ 请求异常: {str(e)}")
|
|||
|
print("-" * 60)
|
|||
|
return False
|
|||
|
|
|||
|
def main():
|
|||
|
print("🧪 简化API测试")
|
|||
|
print("=" * 60)
|
|||
|
|
|||
|
# 测试基本API
|
|||
|
tests = [
|
|||
|
(f"{BASE_URL}/api/stores", "获取店铺列表"),
|
|||
|
(f"{BASE_URL}/api/products", "获取产品列表"),
|
|||
|
(f"{BASE_URL}/api/model_types", "获取模型类型"),
|
|||
|
(f"{BASE_URL}/api/training", "获取训练任务列表"),
|
|||
|
(f"{BASE_URL}/api/training/global/stats", "获取全局训练统计"),
|
|||
|
]
|
|||
|
|
|||
|
success_count = 0
|
|||
|
total_count = len(tests)
|
|||
|
|
|||
|
for url, description in tests:
|
|||
|
if test_get_api(url, description):
|
|||
|
success_count += 1
|
|||
|
|
|||
|
print(f"📊 测试结果: {success_count}/{total_count} 通过")
|
|||
|
|
|||
|
if success_count == total_count:
|
|||
|
print("🎉 所有基本API测试通过!")
|
|||
|
else:
|
|||
|
print("⚠️ 部分API测试失败,请检查服务器状态")
|
|||
|
|
|||
|
if __name__ == "__main__":
|
|||
|
main()
|