58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
快速测试:验证数据库和API
|
||
"""
|
||
|
||
import requests
|
||
import json
|
||
from database import Database
|
||
import os
|
||
|
||
print("="*60)
|
||
print("快速测试")
|
||
print("="*60)
|
||
|
||
# 1. 测试数据库
|
||
print("\n1. 测试数据库查询...")
|
||
db_path = os.path.join(os.path.dirname(__file__), "wrench.db")
|
||
db = Database(db_path)
|
||
available = db.get_available_work_orders("TR20260119001", "P001")
|
||
print(f" 数据库查询结果: {len(available)} 个工单")
|
||
if available:
|
||
print(f" 工单: {available[0]['trace_id']} - {available[0]['process_id']}")
|
||
|
||
# 2. 测试API(如果服务器运行)
|
||
print("\n2. 测试API查询...")
|
||
try:
|
||
response = requests.get(
|
||
"http://localhost:5000/api/work-orders",
|
||
params={"trace_id": "TR20260119001", "process_id": "P001"},
|
||
timeout=2
|
||
)
|
||
if response.status_code == 200:
|
||
data = response.json()
|
||
orders = data.get("data", [])
|
||
print(f" API查询结果: {len(orders)} 个工单")
|
||
if orders:
|
||
print(f" 工单: {orders[0].get('trace_id')} - {orders[0].get('process_id')}")
|
||
else:
|
||
print(" [WARN] API返回空数组,但数据库有数据!")
|
||
print(f" API响应: {json.dumps(data, ensure_ascii=False, indent=2)}")
|
||
else:
|
||
print(f" [FAIL] HTTP {response.status_code}: {response.text}")
|
||
except requests.exceptions.ConnectionError:
|
||
print(" [INFO] API服务器未运行,跳过API测试")
|
||
except Exception as e:
|
||
print(f" [ERROR] API测试失败: {e}")
|
||
|
||
print("\n" + "="*60)
|
||
print("如果数据库有数据但API返回空,请检查:")
|
||
print("1. 后端服务器是否使用正确的数据库路径")
|
||
print("2. 后端服务器日志中的调试信息")
|
||
print("3. 重启后端服务器")
|
||
print("="*60)
|
||
|
||
|
||
|