#!/usr/bin/env python3 """ 创建测试用户以便测试exam模块 """ import asyncio import sys from pathlib import Path # 添加项目根目录到Python路径 project_root = Path(__file__).parent sys.path.insert(0, str(project_root)) from app.core.database import AsyncSessionLocal, engine from app.models.base import Base from app.models.user import User from app.core.security import get_password_hash async def create_test_user(): """创建测试用户""" async with AsyncSessionLocal() as db: try: # 创建一个测试用户 test_user = User( username="test_exam", email="test_exam@example.com", hashed_password=get_password_hash("test123"), full_name="Test Exam User", role="trainee", is_active=True, is_verified=True ) db.add(test_user) await db.commit() await db.refresh(test_user) print(f"✅ 测试用户创建成功:") print(f" 用户名:{test_user.username}") print(f" 邮箱:{test_user.email}") print(f" 密码:test123") print(f" ID:{test_user.id}") except Exception as e: print(f"❌ 创建测试用户失败:{e}") await db.rollback() if __name__ == "__main__": asyncio.run(create_test_user())