feat: 初始化考培练系统项目
- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
This commit is contained in:
50
backend/create_test_user_exam.py
Normal file
50
backend/create_test_user_exam.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/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())
|
||||
Reference in New Issue
Block a user