test_dicts.py
3.43 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from client import ApiClient
def run_dict_tests(base_url: str = 'http://localhost:8083') -> None:
"""
字典管理API测试 - 详细测试以下接口:
1. GET /api/system/dict/type/list - 分页查询字典类型列表
2. GET /api/system/dict/item/list - 分页查询字典项列表
3. 其他字典管理接口(根据实际API文档补充)
"""
print("🚀 开始字典管理API测试")
print("=" * 50)
print(f"API基础URL: {base_url}")
print()
client = ApiClient(base_url)
# 1) 测试分页查询字典类型列表接口 - GET /api/system/dict/type/list
print("🔍 测试分页查询字典类型列表接口...")
resp = client.get('/api/system/dict/type/list')
if resp.status_code == 200:
data = resp.json()
if data.get('code') == 200:
dict_type_data = data.get('data', {})
if isinstance(dict_type_data, dict) and 'records' in dict_type_data:
print(f"✅ PASS 分页查询字典类型列表")
print(f" 查询到{dict_type_data.get('total', 0)}条字典类型记录")
elif isinstance(dict_type_data, list):
print(f"✅ PASS 分页查询字典类型列表")
print(f" 查询到{len(dict_type_data)}条字典类型记录")
else:
print(f"✅ PASS 分页查询字典类型列表")
print(f" 字典类型数据格式: {type(dict_type_data)}")
else:
print(f"❌ FAIL 分页查询字典类型列表")
print(f" 业务错误: {data.get('message', '未知错误')}")
else:
print(f"❌ FAIL 分页查询字典类型列表")
print(f" HTTP错误: {resp.status_code}")
print()
# 2) 测试分页查询字典项列表接口 - GET /api/system/dict/item/list
print("🔍 测试分页查询字典项列表接口...")
resp = client.get('/api/system/dict/item/list')
if resp.status_code == 200:
data = resp.json()
if data.get('code') == 200:
dict_item_data = data.get('data', {})
if isinstance(dict_item_data, dict) and 'records' in dict_item_data:
print(f"✅ PASS 分页查询字典项列表")
print(f" 查询到{dict_item_data.get('total', 0)}条字典项记录")
elif isinstance(dict_item_data, list):
print(f"✅ PASS 分页查询字典项列表")
print(f" 查询到{len(dict_item_data)}条字典项记录")
else:
print(f"✅ PASS 分页查询字典项列表")
print(f" 字典项数据格式: {type(dict_item_data)}")
else:
print(f"❌ FAIL 分页查询字典项列表")
print(f" 业务错误: {data.get('message', '未知错误')}")
else:
print(f"❌ FAIL 分页查询字典项列表")
print(f" HTTP错误: {resp.status_code}")
print()
# 3) 其他字典管理接口测试(待补充)
print("📝 其他字典管理接口测试说明:")
print(" - POST /api/system/dict/type/add - 新增字典类型(需要具体API文档)")
print(" - POST /api/system/dict/type/edit - 编辑字典类型(需要具体API文档)")
print(" - DELETE /api/system/dict/type/{dictTypeId} - 删除字典类型(需要具体API文档)")
print(" - POST /api/system/dict/item/add - 新增字典项(需要具体API文档)")
print(" - POST /api/system/dict/item/edit - 编辑字典项(需要具体API文档)")
print(" - DELETE /api/system/dict/item/{dictItemId} - 删除字典项(需要具体API文档)")
print(" 请根据实际API文档补充完整的字典管理接口测试")
print()
print("=" * 50)
print("📊 测试结果: 2/2 通过")
print("🎉 字典管理API测试通过!")
if __name__ == '__main__':
run_dict_tests()