baoxiang/test_api.py

31 lines
911 B
Python
Raw Normal View History

2025-12-16 18:06:50 +08:00
#!/usr/bin/env python3
"""
测试API接口
"""
import requests
import json
def test_api():
"""测试API接口"""
print("=== 测试API接口 ===")
try:
# 测试获取宝箱列表
response = requests.get("http://localhost:8000/api/chests")
print(f"Status Code: {response.status_code}")
print(f"Headers: {response.headers}")
if response.status_code == 200:
chests = response.json()
print(f"获取到 {len(chests)} 个宝箱")
print("宝箱数据:")
for chest in chests:
print(f" ID: {chest['id']}, Title: {chest['title']}, Status: {chest['status']}, Time Remaining: {chest.get('time_remaining', 'N/A')}")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"请求错误: {e}")
if __name__ == "__main__":
test_api()