zhouhui.jiang

update 更新API测试

{
"token": "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwic3ViIjoiYWRtaW4iLCJpYXQiOjE3NjAzMjIyMzAsImV4cCI6MTc2MDQwODYzMH0.qN7qoSDl35jIDw2tVy4sZwAjymJYaHQFaOdExnXmG7_g4wqxUCUioBxbRcf9Jrkgz-7_HlClNBNqOlYtc20roQ",
"saved_at": 1760322230
"token": "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwic3ViIjoiYWRtaW4iLCJpYXQiOjE3NjAzMjYxMTksImV4cCI6MTc2MDQxMjUxOX0.QiJRc8xCQN_MBEwH3BRK5fUW17pz_9s7fCvFJK1AIbqg8uqhezw-FVxUi7G5-gIf4zlJrovZpMB0VGg7xT3XDg",
"saved_at": 1760326119
}
\ No newline at end of file
......
......@@ -7,27 +7,6 @@ Python 3.7.8 兼容
import os
import sys
import subprocess
from typing import List, Tuple
def run_script(script_path: str, args: List[str] = None) -> Tuple[bool, str]:
"""运行单个测试脚本"""
cmd = [sys.executable, script_path]
if args:
cmd.extend(args)
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
cwd=os.path.dirname(__file__)
)
return result.returncode == 0, result.stdout + result.stderr
except Exception as e:
return False, str(e)
def main():
"""主函数:按顺序运行所有测试"""
......@@ -37,36 +16,56 @@ def main():
# 测试脚本列表(按执行顺序)
tests = [
("认证登录测试", "test_auth.py", ["admin", "password"]),
("用户管理测试", "test_users.py", []),
("角色管理测试", "test_roles.py", []),
("菜单管理测试", "test_menus.py", []),
("字典管理测试", "test_dicts.py", []),
("认证登录测试", "test_auth.py"),
("用户管理测试", "test_users.py"),
("角色管理测试", "test_roles.py"),
("菜单管理测试", "test_menus.py"),
("字典管理测试", "test_dicts.py"),
]
success_count = 0
total_count = len(tests)
for test_name, script_name, args in tests:
for test_name, script_name in tests:
print(f"\n{'='*20} {test_name} {'='*20}")
script_path = os.path.join(os.path.dirname(__file__), script_name)
if not os.path.exists(script_path):
print(f"❌ 脚本不存在: {script_path}")
if not os.path.exists(script_name):
print(f"❌ 脚本不存在: {script_name}")
continue
success, output = run_script(script_path, args)
if success:
print(f"✅ {test_name} 执行成功")
success_count += 1
else:
print(f"❌ {test_name} 执行失败")
# 显示输出(截取前500字符避免过长)
if output:
print("输出:")
print(output[:500] + ("..." if len(output) > 500 else ""))
try:
# 直接导入并运行测试函数
module_name = script_name.replace('.py', '')
if module_name == 'test_auth':
from test_auth import login_and_print_token
success, _ = login_and_print_token('admin', 'password')
if success:
print(f"✅ {test_name} 执行成功")
success_count += 1
else:
print(f"❌ {test_name} 执行失败")
elif module_name == 'test_users':
from test_users import run_user_tests
run_user_tests()
print(f"✅ {test_name} 执行成功")
success_count += 1
elif module_name == 'test_roles':
from test_roles import run_role_tests
run_role_tests()
print(f"✅ {test_name} 执行成功")
success_count += 1
elif module_name == 'test_menus':
from test_menus import run_menu_tests
run_menu_tests()
print(f"✅ {test_name} 执行成功")
success_count += 1
elif module_name == 'test_dicts':
from test_dicts import run_dict_tests
run_dict_tests()
print(f"✅ {test_name} 执行成功")
success_count += 1
except Exception as e:
print(f"❌ {test_name} 执行失败: {e}")
# 总结
print("\n" + "=" * 60)
......@@ -80,6 +79,5 @@ def main():
print("⚠️ 部分测试失败,请检查输出信息")
return 1
if __name__ == "__main__":
sys.exit(main())
......
......@@ -3,14 +3,16 @@ from client import ApiClient
def run_dict_tests(base_url: str = 'http://localhost:8083') -> None:
client = ApiClient(base_url)
# 文档未找到明确的字典接口路径,这里提供占位尝试
possible_list = ['/api/system/dict/list', '/api/dict/list']
for path in possible_list:
resp = client.get(path)
print('字典列表(尝试路径=', path, ') status=', resp.status_code)
print(resp.text)
if resp.status_code == 200:
break
# 1) 字典类型列表
resp = client.get('/api/system/dict/type/list')
print('字典类型列表 status=', resp.status_code)
print(resp.text)
# 2) 字典项列表
resp = client.get('/api/system/dict/item/list')
print('字典项列表 status=', resp.status_code)
print(resp.text)
if __name__ == '__main__':
......