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

54 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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 urllib.request
import json
def test_new_endpoint():
try:
print("=== 测试新端点 /api/models/test ===")
url = 'http://localhost:5000/api/models/test'
with urllib.request.urlopen(url) as response:
data = response.read().decode('utf-8')
result = json.loads(data)
print(f"响应状态: {response.status}")
print(f"测试名称: {result.get('test_name', 'N/A')}")
print(f"模型目录: {result.get('model_dir', 'N/A')}")
print(f"目录存在: {result.get('dir_exists', 'N/A')}")
print(f"找到模型: {result.get('models_found', 0)}")
models = result.get('models', [])
for i, model in enumerate(models):
print(f"\n模型 {i+1}:")
print(f" filename: '{model.get('filename', 'MISSING')}'")
print(f" model_id: '{model.get('model_id', 'MISSING')}'")
print(f" product_id: '{model.get('product_id', 'MISSING')}'")
print(f" model_type: '{model.get('model_type', 'MISSING')}'")
if model.get('filename') != 'MISSING' and model.get('model_id') != 'GENERATED_MISSING':
print(" ✓ 该模型数据正常")
else:
print(" ✗ 该模型数据有问题")
if result.get('models_found', 0) > 0:
working_models = sum(1 for m in models
if m.get('filename') != 'MISSING' and m.get('model_id') != 'GENERATED_MISSING')
if working_models == result.get('models_found', 0):
print(f"\n✓ 新端点测试成功!所有 {working_models} 个模型数据正常")
print("✓ ModelManager修复已生效")
print("✓ 应该重启API服务器以应用到主端点 /api/models")
else:
print(f"\n⚠ 部分模型有问题: {working_models}/{result.get('models_found', 0)} 正常")
else:
print("\n✗ 没有找到模型文件")
except urllib.error.HTTPError as e:
print(f"HTTP错误: {e.code} - 可能端点不存在需要重启API服务器")
except Exception as e:
print(f"测试失败: {e}")
if __name__ == "__main__":
test_new_endpoint()