zhouhui.jiang

update 更新API测试

1 { 1 {
2 - "token": "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwic3ViIjoiYWRtaW4iLCJpYXQiOjE3NjAzMjIyMzAsImV4cCI6MTc2MDQwODYzMH0.qN7qoSDl35jIDw2tVy4sZwAjymJYaHQFaOdExnXmG7_g4wqxUCUioBxbRcf9Jrkgz-7_HlClNBNqOlYtc20roQ", 2 + "token": "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwic3ViIjoiYWRtaW4iLCJpYXQiOjE3NjAzMjYxMTksImV4cCI6MTc2MDQxMjUxOX0.QiJRc8xCQN_MBEwH3BRK5fUW17pz_9s7fCvFJK1AIbqg8uqhezw-FVxUi7G5-gIf4zlJrovZpMB0VGg7xT3XDg",
3 - "saved_at": 1760322230 3 + "saved_at": 1760326119
4 } 4 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,27 +7,6 @@ Python 3.7.8 兼容 ...@@ -7,27 +7,6 @@ Python 3.7.8 兼容
7 7
8 import os 8 import os
9 import sys 9 import sys
10 -import subprocess
11 -from typing import List, Tuple
12 -
13 -
14 -def run_script(script_path: str, args: List[str] = None) -> Tuple[bool, str]:
15 - """运行单个测试脚本"""
16 - cmd = [sys.executable, script_path]
17 - if args:
18 - cmd.extend(args)
19 -
20 - try:
21 - result = subprocess.run(
22 - cmd,
23 - capture_output=True,
24 - text=True,
25 - cwd=os.path.dirname(__file__)
26 - )
27 - return result.returncode == 0, result.stdout + result.stderr
28 - except Exception as e:
29 - return False, str(e)
30 -
31 10
32 def main(): 11 def main():
33 """主函数:按顺序运行所有测试""" 12 """主函数:按顺序运行所有测试"""
...@@ -37,36 +16,56 @@ def main(): ...@@ -37,36 +16,56 @@ def main():
37 16
38 # 测试脚本列表(按执行顺序) 17 # 测试脚本列表(按执行顺序)
39 tests = [ 18 tests = [
40 - ("认证登录测试", "test_auth.py", ["admin", "password"]), 19 + ("认证登录测试", "test_auth.py"),
41 - ("用户管理测试", "test_users.py", []), 20 + ("用户管理测试", "test_users.py"),
42 - ("角色管理测试", "test_roles.py", []), 21 + ("角色管理测试", "test_roles.py"),
43 - ("菜单管理测试", "test_menus.py", []), 22 + ("菜单管理测试", "test_menus.py"),
44 - ("字典管理测试", "test_dicts.py", []), 23 + ("字典管理测试", "test_dicts.py"),
45 ] 24 ]
46 25
47 success_count = 0 26 success_count = 0
48 total_count = len(tests) 27 total_count = len(tests)
49 28
50 - for test_name, script_name, args in tests: 29 + for test_name, script_name in tests:
51 print(f"\n{'='*20} {test_name} {'='*20}") 30 print(f"\n{'='*20} {test_name} {'='*20}")
52 - script_path = os.path.join(os.path.dirname(__file__), script_name)
53 31
54 - if not os.path.exists(script_path): 32 + if not os.path.exists(script_name):
55 - print(f"❌ 脚本不存在: {script_path}") 33 + print(f"❌ 脚本不存在: {script_name}")
56 continue 34 continue
57 -
58 - success, output = run_script(script_path, args)
59 -
60 - if success:
61 - print(f"✅ {test_name} 执行成功")
62 - success_count += 1
63 - else:
64 - print(f"❌ {test_name} 执行失败")
65 35
66 - # 显示输出(截取前500字符避免过长) 36 + try:
67 - if output: 37 + # 直接导入并运行测试函数
68 - print("输出:") 38 + module_name = script_name.replace('.py', '')
69 - print(output[:500] + ("..." if len(output) > 500 else "")) 39 + if module_name == 'test_auth':
40 + from test_auth import login_and_print_token
41 + success, _ = login_and_print_token('admin', 'password')
42 + if success:
43 + print(f"✅ {test_name} 执行成功")
44 + success_count += 1
45 + else:
46 + print(f"❌ {test_name} 执行失败")
47 + elif module_name == 'test_users':
48 + from test_users import run_user_tests
49 + run_user_tests()
50 + print(f"✅ {test_name} 执行成功")
51 + success_count += 1
52 + elif module_name == 'test_roles':
53 + from test_roles import run_role_tests
54 + run_role_tests()
55 + print(f"✅ {test_name} 执行成功")
56 + success_count += 1
57 + elif module_name == 'test_menus':
58 + from test_menus import run_menu_tests
59 + run_menu_tests()
60 + print(f"✅ {test_name} 执行成功")
61 + success_count += 1
62 + elif module_name == 'test_dicts':
63 + from test_dicts import run_dict_tests
64 + run_dict_tests()
65 + print(f"✅ {test_name} 执行成功")
66 + success_count += 1
67 + except Exception as e:
68 + print(f"❌ {test_name} 执行失败: {e}")
70 69
71 # 总结 70 # 总结
72 print("\n" + "=" * 60) 71 print("\n" + "=" * 60)
...@@ -80,6 +79,5 @@ def main(): ...@@ -80,6 +79,5 @@ def main():
80 print("⚠️ 部分测试失败,请检查输出信息") 79 print("⚠️ 部分测试失败,请检查输出信息")
81 return 1 80 return 1
82 81
83 -
84 if __name__ == "__main__": 82 if __name__ == "__main__":
85 sys.exit(main()) 83 sys.exit(main())
......
...@@ -3,14 +3,16 @@ from client import ApiClient ...@@ -3,14 +3,16 @@ from client import ApiClient
3 3
4 def run_dict_tests(base_url: str = 'http://localhost:8083') -> None: 4 def run_dict_tests(base_url: str = 'http://localhost:8083') -> None:
5 client = ApiClient(base_url) 5 client = ApiClient(base_url)
6 - # 文档未找到明确的字典接口路径,这里提供占位尝试 6 +
7 - possible_list = ['/api/system/dict/list', '/api/dict/list'] 7 + # 1) 字典类型列表
8 - for path in possible_list: 8 + resp = client.get('/api/system/dict/type/list')
9 - resp = client.get(path) 9 + print('字典类型列表 status=', resp.status_code)
10 - print('字典列表(尝试路径=', path, ') status=', resp.status_code) 10 + print(resp.text)
11 - print(resp.text) 11 +
12 - if resp.status_code == 200: 12 + # 2) 字典项列表
13 - break 13 + resp = client.get('/api/system/dict/item/list')
14 + print('字典项列表 status=', resp.status_code)
15 + print(resp.text)
14 16
15 17
16 if __name__ == '__main__': 18 if __name__ == '__main__':
......