-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_format.py
More file actions
53 lines (43 loc) · 1.84 KB
/
test_api_format.py
File metadata and controls
53 lines (43 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
测试脚本:验证API返回的数据格式
"""
import requests
import json
# 测试本地环境
LOCAL_URL = "http://localhost:7777"
def test_api():
print("测试API数据格式...")
print("="*60)
# 注意:需要先登录才能访问API
print("\n⚠️ 此脚本需要在已登录的浏览器中运行")
print("或者修改脚本添加登录逻辑\n")
try:
# 测试API端点
response = requests.get(f"{LOCAL_URL}/api/punches")
if response.status_code == 200:
data = response.json()
print("✓ API响应成功")
print(f"\n返回的数据结构:")
print(json.dumps(data, indent=2, ensure_ascii=False))
# 分析数据结构
if data:
first_date = list(data.keys())[0]
first_records = data[first_date]
print(f"\n第一个日期: {first_date}")
print(f"记录数: {len(first_records)}")
if first_records:
first_record = first_records[0]
print(f"\n第一条记录的类型: {type(first_record)}")
print(f"第一条记录的内容: {first_record}")
if isinstance(first_record, dict):
print("\n✓ 记录是对象格式(新格式)")
print(f" 包含的字段: {list(first_record.keys())}")
elif isinstance(first_record, str):
print("\n✓ 记录是字符串格式(旧格式)")
else:
print(f"✗ API响应失败: {response.status_code}")
print(f" 错误信息: {response.text}")
except Exception as e:
print(f"✗ 测试失败: {e}")
if __name__ == "__main__":
test_api()