Files
assist/test_refactor.py
zhaojie 2026007045 refactor: 移除冗余文件并优化代码结构
- 删除多个不再使用的脚本和配置文件,包括 `auto_push.bat`, `check_and_fix_users.py`, `init.sql` 等。
- 新增 `git_push.bat` 和 `git_push.sh` 脚本以简化 Git 推送流程。
- 更新 `README.md` 以反映最新的功能和结构变化。
- 优化前端代码,添加新的页面和组件,提升用户体验。

此提交旨在清理项目结构并增强代码可维护性。
2025-12-08 00:53:23 +08:00

92 lines
2.6 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试重构后的应用
"""
import sys
import os
# 添加项目路径
sys.path.append('src')
def test_blueprints():
"""测试蓝图注册"""
try:
from src.web.app import app
print("✓ Flask应用导入成功")
# 测试蓝图注册
blueprints = list(app.blueprints.keys())
print(f"✓ 已注册蓝图: {blueprints}")
expected_blueprints = [
'alerts', 'workorders', 'conversations', 'knowledge',
'monitoring', 'system', 'feishu_sync', 'core', 'auth',
'agent', 'vehicle', 'analytics', 'test'
]
for bp in expected_blueprints:
if bp in blueprints:
print(f"✓ 蓝图 {bp} 已注册")
else:
print(f"✗ 蓝图 {bp} 未注册")
# 测试路由
routes = [str(rule) for rule in app.url_map.iter_rules()]
agent_routes = [r for r in routes if 'agent' in r]
vehicle_routes = [r for r in routes if 'vehicle' in r]
analytics_routes = [r for r in routes if 'analytics' in r]
print(f"✓ Agent相关路由数量: {len(agent_routes)}")
print(f"✓ Vehicle相关路由数量: {len(vehicle_routes)}")
print(f"✓ Analytics相关路由数量: {len(analytics_routes)}")
return True
except Exception as e:
print(f"✗ 应用测试失败: {e}")
import traceback
traceback.print_exc()
return False
def test_blueprint_imports():
"""测试蓝图模块导入"""
blueprints_to_test = [
('src.web.blueprints.agent', 'agent_bp'),
('src.web.blueprints.vehicle', 'vehicle_bp'),
('src.web.blueprints.analytics', 'analytics_bp'),
('src.web.blueprints.test', 'test_bp'),
]
for module_name, bp_name in blueprints_to_test:
try:
module = __import__(module_name, fromlist=[bp_name])
bp = getattr(module, bp_name)
print(f"{module_name}.{bp_name} 导入成功")
except Exception as e:
print(f"{module_name}.{bp_name} 导入失败: {e}")
return False
return True
if __name__ == '__main__':
print("开始测试重构后的应用...")
print("=" * 50)
success = True
print("\n1. 测试蓝图模块导入...")
success &= test_blueprint_imports()
print("\n2. 测试Flask应用和蓝图注册...")
success &= test_blueprints()
print("\n" + "=" * 50)
if success:
print("✓ 所有测试通过!重构成功!")
else:
print("✗ 部分测试失败,请检查代码")
sys.exit(1)