ShopTRAINING/test/test_api_simple.py
2025-07-02 11:05:23 +08:00

56 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
简单API测试
"""
import requests
import json
def test_models_api():
"""测试模型API"""
api_url = "http://localhost:5000/api/models"
try:
print("请求API:", api_url)
response = requests.get(api_url, timeout=10)
print(f"状态码: {response.status_code}")
if response.status_code == 200:
data = response.json()
print("API响应结构:")
print(f" status: {data.get('status')}")
print(f" total: {data.get('total')}")
models = data.get('data', [])
print(f" models count: {len(models)}")
for i, model in enumerate(models):
print(f"\n模型 {i+1}:")
print(f" model_id: '{model.get('model_id', 'MISSING')}'")
print(f" filename: '{model.get('filename', 'MISSING')}'")
print(f" product_id: '{model.get('product_id', 'MISSING')}'")
print(f" model_type: '{model.get('model_type', 'MISSING')}'")
print(f" version: '{model.get('version', 'MISSING')}'")
# 分析问题
if not model.get('model_id'):
print(" ❌ model_id为空!")
if not model.get('filename'):
print(" ❌ filename也为空!")
else:
print(f" filename存在: {model.get('filename')}")
else:
print(" ✅ model_id正常")
else:
print(f"请求失败: {response.text}")
except requests.exceptions.ConnectionError:
print("❌ 无法连接到API服务器")
print("请确保API服务器正在运行: python server/api.py")
except Exception as e:
print(f"测试失败: {e}")
if __name__ == "__main__":
test_models_api()