run_all_tests.py 2.68 KB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
运行所有API测试脚本
Python 3.7.8 兼容
"""

import os
import sys

def main():
    """主函数:按顺序运行所有测试"""
    print("=" * 60)
    print("Apple ERP API 测试套件")
    print("=" * 60)
    
    # 测试脚本列表(按执行顺序)
    tests = [
        ("认证登录测试", "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 in tests:
        print(f"\n{'='*20} {test_name} {'='*20}")
        
        if not os.path.exists(script_name):
            print(f"❌ 脚本不存在: {script_name}")
            continue
        
        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)
    print(f"测试完成: {success_count}/{total_count} 个测试通过")
    print("=" * 60)
    
    if success_count == total_count:
        print("🎉 所有测试都通过了!")
        return 0
    else:
        print("⚠️  部分测试失败,请检查输出信息")
        return 1

if __name__ == "__main__":
    sys.exit(main())