TorqueWrench/backend/test_api.py

45 lines
1.1 KiB
Python
Raw Normal View History

2026-01-24 02:54:01 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
测试API接口
"""
import requests
import json
API_BASE = "http://localhost:5000/api"
def test_query():
"""测试查询接口"""
print("="*60)
print("测试查询工单接口")
print("="*60)
params = {
"trace_id": "TR20260119001",
"process_id": "P001"
}
try:
response = requests.get(f"{API_BASE}/work-orders", params=params, timeout=5)
print(f"状态码: {response.status_code}")
print(f"响应: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
data = response.json()
if data.get("success"):
orders = data.get("data", [])
print(f"\n找到 {len(orders)} 个可用工单")
for order in orders:
print(f" - {order.get('trace_id')} | {order.get('process_id')} | {order.get('process_name')}")
else:
print(f"\n查询失败: {data.get('message')}")
except Exception as e:
print(f"请求失败: {e}")
if __name__ == "__main__":
test_query()
2026-02-04 11:35:09 +08:00