633 lines
21 KiB
Python
633 lines
21 KiB
Python
from sqlalchemy.orm import Session
|
||
from database import SessionLocal, engine
|
||
import models
|
||
import datetime
|
||
|
||
def seed():
|
||
models.Base.metadata.create_all(bind=engine)
|
||
db = SessionLocal()
|
||
|
||
# Clear existing data for a clean seed
|
||
db.query(models.TestTask).delete()
|
||
db.query(models.TestCase).delete()
|
||
db.commit()
|
||
|
||
# ============================================================
|
||
# 根据 case.md 生成完整的测试用例数据
|
||
# 模块结构:
|
||
# - 用户管理模块
|
||
# - 登录功能
|
||
# - 注册功能
|
||
# - 权限管理
|
||
# - 订单管理模块
|
||
# - 创建订单
|
||
# - 支付流程
|
||
# - 退款流程
|
||
# - 商品管理模块
|
||
# - 商品搜索
|
||
# - 商品详情
|
||
# - 系统设置模块
|
||
# - 通知配置
|
||
# - 个人中心
|
||
# ============================================================
|
||
|
||
mock_cases = [
|
||
# ==================== 用户管理模块 ====================
|
||
{
|
||
"id": "mod-user",
|
||
"case_id": None,
|
||
"text": "用户管理模块",
|
||
"module": "用户管理",
|
||
"type": "General",
|
||
"priority": None,
|
||
"review_status": "Reviewed",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": None,
|
||
"parent_id": None,
|
||
"tags": '["核心模块"]'
|
||
},
|
||
# -- 登录功能 子目录 --
|
||
{
|
||
"id": "dir-login",
|
||
"case_id": None,
|
||
"text": "登录功能",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"review_status": "Reviewed",
|
||
"maintainer": None,
|
||
"parent_id": "mod-user",
|
||
"tags": '["登录"]'
|
||
},
|
||
{
|
||
"id": "tc-001",
|
||
"case_id": "TC-001",
|
||
"text": "账号密码正确登录成功",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "张三",
|
||
"requirement_id": "REQ-1001",
|
||
"parent_id": "dir-login",
|
||
"steps": '[{"action": "打开登录页面", "expected": "登录页正常展示"}, {"action": "输入正确的账号密码点击登录", "expected": "登录成功跳转到首页"}]',
|
||
"tags": '["冒烟", "核心流程"]'
|
||
},
|
||
{
|
||
"id": "tc-002",
|
||
"case_id": "TC-002",
|
||
"text": "手机验证码登录",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "张三",
|
||
"requirement_id": "REQ-1001",
|
||
"parent_id": "dir-login",
|
||
"steps": '[{"action": "输入手机号获取验证码", "expected": "验证码发送成功"}, {"action": "输入正确验证码点击登录", "expected": "登录成功"}]',
|
||
"tags": '["冒烟"]'
|
||
},
|
||
{
|
||
"id": "tc-003",
|
||
"case_id": "TC-003",
|
||
"text": "第三方微信扫码登录",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "李四",
|
||
"requirement_id": "REQ-1002",
|
||
"parent_id": "dir-login",
|
||
"steps": '[{"action": "点击微信登录图标", "expected": "弹出二维码"}, {"action": "手机扫码确认", "expected": "登录成功跳转首页"}]',
|
||
"tags": '["需求"]'
|
||
},
|
||
{
|
||
"id": "tc-004",
|
||
"case_id": "TC-004",
|
||
"text": "密码错误登录失败提示",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "FAIL",
|
||
"maintainer": "张三",
|
||
"bug_id": "BUG-001",
|
||
"parent_id": "dir-login",
|
||
"steps": '[{"action": "输入正确账号和错误密码", "expected": "提示密码错误"}, {"action": "连续5次错误输入", "expected": "账号被锁定15分钟"}]',
|
||
"tags": '["回归"]'
|
||
},
|
||
{
|
||
"id": "tc-005",
|
||
"case_id": "TC-005",
|
||
"text": "登录状态过期自动跳转",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "Draft",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "张三",
|
||
"parent_id": "dir-login",
|
||
"tags": '["回归"]'
|
||
},
|
||
# -- 注册功能 子目录 --
|
||
{
|
||
"id": "dir-register",
|
||
"case_id": None,
|
||
"text": "注册功能",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-user",
|
||
},
|
||
{
|
||
"id": "tc-006",
|
||
"case_id": "TC-006",
|
||
"text": "手机号注册新账号",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "李四",
|
||
"requirement_id": "REQ-1003",
|
||
"parent_id": "dir-register",
|
||
"steps": '[{"action": "输入手机号获取验证码", "expected": "验证码发送成功"}, {"action": "填写信息提交注册", "expected": "注册成功自动登录"}]',
|
||
"tags": '["冒烟", "核心流程"]'
|
||
},
|
||
{
|
||
"id": "tc-007",
|
||
"case_id": "TC-007",
|
||
"text": "邮箱注册新账号",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "李四",
|
||
"parent_id": "dir-register",
|
||
"tags": '["需求"]'
|
||
},
|
||
{
|
||
"id": "tc-008",
|
||
"case_id": "TC-008",
|
||
"text": "重复手机号注册校验",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "FAIL",
|
||
"maintainer": "李四",
|
||
"bug_id": "BUG-002",
|
||
"parent_id": "dir-register",
|
||
"tags": '["回归"]'
|
||
},
|
||
# -- 权限管理 子目录 --
|
||
{
|
||
"id": "dir-perm",
|
||
"case_id": None,
|
||
"text": "权限管理",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-user",
|
||
},
|
||
{
|
||
"id": "tc-009",
|
||
"case_id": "TC-009",
|
||
"text": "管理员角色权限验证",
|
||
"module": "用户管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-perm",
|
||
"tags": '["冒烟", "权限"]'
|
||
},
|
||
{
|
||
"id": "tc-010",
|
||
"case_id": "TC-010",
|
||
"text": "普通用户越权访问拦截",
|
||
"module": "用户管理",
|
||
"type": "API",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-perm",
|
||
"tags": '["安全", "回归"]'
|
||
},
|
||
|
||
# ==================== 订单管理模块 ====================
|
||
{
|
||
"id": "mod-order",
|
||
"case_id": None,
|
||
"text": "订单管理模块",
|
||
"module": "订单管理",
|
||
"type": "General",
|
||
"priority": None,
|
||
"parent_id": None,
|
||
"tags": '["核心模块"]'
|
||
},
|
||
# -- 创建订单 --
|
||
{
|
||
"id": "dir-create-order",
|
||
"case_id": None,
|
||
"text": "创建订单",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-order",
|
||
},
|
||
{
|
||
"id": "tc-011",
|
||
"case_id": "TC-011",
|
||
"text": "正常商品下单流程",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "赵六",
|
||
"requirement_id": "REQ-2001",
|
||
"parent_id": "dir-create-order",
|
||
"steps": '[{"action": "选择商品加入购物车", "expected": "商品添加成功"}, {"action": "点击结算提交订单", "expected": "订单创建成功显示待支付"}]',
|
||
"tags": '["冒烟", "核心流程"]'
|
||
},
|
||
{
|
||
"id": "tc-012",
|
||
"case_id": "TC-012",
|
||
"text": "库存不足下单提示",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "赵六",
|
||
"parent_id": "dir-create-order",
|
||
"tags": '["回归"]'
|
||
},
|
||
{
|
||
"id": "tc-013",
|
||
"case_id": "TC-013",
|
||
"text": "优惠券叠加使用校验",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "Draft",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "赵六",
|
||
"parent_id": "dir-create-order",
|
||
"tags": '["需求"]'
|
||
},
|
||
# -- 支付流程 --
|
||
{
|
||
"id": "dir-payment",
|
||
"case_id": None,
|
||
"text": "支付流程",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-order",
|
||
},
|
||
{
|
||
"id": "tc-014",
|
||
"case_id": "TC-014",
|
||
"text": "微信支付成功场景",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "赵六",
|
||
"requirement_id": "REQ-2002",
|
||
"parent_id": "dir-payment",
|
||
"steps": '[{"action": "选择微信支付", "expected": "唤起微信支付"}, {"action": "确认支付", "expected": "支付成功跳转订单详情"}]',
|
||
"tags": '["冒烟", "核心流程"]'
|
||
},
|
||
{
|
||
"id": "tc-015",
|
||
"case_id": "TC-015",
|
||
"text": "支付宝支付成功场景",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "赵六",
|
||
"parent_id": "dir-payment",
|
||
"tags": '["冒烟"]'
|
||
},
|
||
{
|
||
"id": "tc-016",
|
||
"case_id": "TC-016",
|
||
"text": "余额不足支付失败",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "FAIL",
|
||
"maintainer": "张三",
|
||
"bug_id": "BUG-003",
|
||
"parent_id": "dir-payment",
|
||
"tags": '["回归"]'
|
||
},
|
||
{
|
||
"id": "tc-017",
|
||
"case_id": "TC-017",
|
||
"text": "支付超时自动取消订单",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "PendingReview",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "张三",
|
||
"parent_id": "dir-payment",
|
||
"tags": '["回归"]'
|
||
},
|
||
# -- 退款流程 --
|
||
{
|
||
"id": "dir-refund",
|
||
"case_id": None,
|
||
"text": "退款流程",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-order",
|
||
},
|
||
{
|
||
"id": "tc-018",
|
||
"case_id": "TC-018",
|
||
"text": "已支付订单申请退款",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "李四",
|
||
"requirement_id": "REQ-2003",
|
||
"parent_id": "dir-refund",
|
||
"steps": '[{"action": "进入订单详情点击申请退款", "expected": "退款申请提交成功"}, {"action": "审核通过", "expected": "退款到账通知"}]',
|
||
"tags": '["冒烟", "核心流程"]'
|
||
},
|
||
{
|
||
"id": "tc-019",
|
||
"case_id": "TC-019",
|
||
"text": "部分退款金额校验",
|
||
"module": "订单管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "李四",
|
||
"parent_id": "dir-refund",
|
||
"tags": '["需求"]'
|
||
},
|
||
|
||
# ==================== 商品管理模块 ====================
|
||
{
|
||
"id": "mod-product",
|
||
"case_id": None,
|
||
"text": "商品管理模块",
|
||
"module": "商品管理",
|
||
"type": "General",
|
||
"priority": None,
|
||
"parent_id": None,
|
||
"tags": '["核心模块"]'
|
||
},
|
||
{
|
||
"id": "dir-search",
|
||
"case_id": None,
|
||
"text": "商品搜索",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-product",
|
||
},
|
||
{
|
||
"id": "tc-020",
|
||
"case_id": "TC-020",
|
||
"text": "关键词精确搜索商品",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-search",
|
||
"steps": '[{"action": "输入商品名称搜索", "expected": "返回匹配的商品列表"}]',
|
||
"tags": '["冒烟"]'
|
||
},
|
||
{
|
||
"id": "tc-021",
|
||
"case_id": "TC-021",
|
||
"text": "筛选条件组合搜索",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-search",
|
||
"tags": '["需求"]'
|
||
},
|
||
{
|
||
"id": "tc-022",
|
||
"case_id": "TC-022",
|
||
"text": "搜索无结果页面展示",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "Draft",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-search",
|
||
"tags": '["回归"]'
|
||
},
|
||
{
|
||
"id": "dir-product-detail",
|
||
"case_id": None,
|
||
"text": "商品详情",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-product",
|
||
},
|
||
{
|
||
"id": "tc-023",
|
||
"case_id": "TC-023",
|
||
"text": "商品详情页信息展示",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": "P0",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-product-detail",
|
||
"tags": '["冒烟"]'
|
||
},
|
||
{
|
||
"id": "tc-024",
|
||
"case_id": "TC-024",
|
||
"text": "商品评价列表分页",
|
||
"module": "商品管理",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "PendingReview",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "王五",
|
||
"parent_id": "dir-product-detail",
|
||
"tags": '["需求"]'
|
||
},
|
||
|
||
# ==================== 系统设置模块 ====================
|
||
{
|
||
"id": "mod-settings",
|
||
"case_id": None,
|
||
"text": "系统设置模块",
|
||
"module": "系统设置",
|
||
"type": "General",
|
||
"priority": None,
|
||
"parent_id": None,
|
||
"tags": '["基础模块"]'
|
||
},
|
||
{
|
||
"id": "dir-notification",
|
||
"case_id": None,
|
||
"text": "通知配置",
|
||
"module": "系统设置",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-settings",
|
||
},
|
||
{
|
||
"id": "tc-025",
|
||
"case_id": "TC-025",
|
||
"text": "站内消息通知开关",
|
||
"module": "系统设置",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "Draft",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "赵六",
|
||
"parent_id": "dir-notification",
|
||
"tags": '["自测"]'
|
||
},
|
||
{
|
||
"id": "tc-026",
|
||
"case_id": "TC-026",
|
||
"text": "邮件通知模板配置",
|
||
"module": "系统设置",
|
||
"type": "Web",
|
||
"priority": "P3",
|
||
"review_status": "Draft",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "赵六",
|
||
"parent_id": "dir-notification",
|
||
"tags": '["自测"]'
|
||
},
|
||
{
|
||
"id": "dir-profile",
|
||
"case_id": None,
|
||
"text": "个人中心",
|
||
"module": "系统设置",
|
||
"type": "Web",
|
||
"priority": None,
|
||
"parent_id": "mod-settings",
|
||
},
|
||
{
|
||
"id": "tc-027",
|
||
"case_id": "TC-027",
|
||
"text": "个人信息修改保存",
|
||
"module": "系统设置",
|
||
"type": "Web",
|
||
"priority": "P1",
|
||
"review_status": "Reviewed",
|
||
"execution_status": "PASS",
|
||
"maintainer": "李四",
|
||
"parent_id": "dir-profile",
|
||
"tags": '["自测"]'
|
||
},
|
||
{
|
||
"id": "tc-028",
|
||
"case_id": "TC-028",
|
||
"text": "头像上传与裁剪",
|
||
"module": "系统设置",
|
||
"type": "Web",
|
||
"priority": "P2",
|
||
"review_status": "PendingReview",
|
||
"execution_status": "UNTESTED",
|
||
"maintainer": "李四",
|
||
"parent_id": "dir-profile",
|
||
"tags": '["需求"]'
|
||
},
|
||
]
|
||
|
||
import json
|
||
for case_data in mock_cases:
|
||
# Parse JSON strings for steps and tags
|
||
if "steps" in case_data and isinstance(case_data["steps"], str):
|
||
case_data["steps"] = json.loads(case_data["steps"])
|
||
if "tags" in case_data and isinstance(case_data["tags"], str):
|
||
case_data["tags"] = json.loads(case_data["tags"])
|
||
|
||
# Remove None priority for directory nodes
|
||
if case_data.get("priority") is None:
|
||
case_data.pop("priority", None)
|
||
|
||
db_case = models.TestCase(**case_data)
|
||
db.add(db_case)
|
||
|
||
# ============================================================
|
||
# 测试任务 - 覆盖4种类型(回归、需求、自测、冒烟)
|
||
# ============================================================
|
||
now = datetime.datetime.now().isoformat()
|
||
mock_tasks = [
|
||
{
|
||
"id": "task-smoke-1",
|
||
"name": "v3.0 核心流程冒烟测试",
|
||
"status": "RUNNING",
|
||
"plan_id": "plan-smoke",
|
||
"assignee": "张三",
|
||
"created_at": now
|
||
},
|
||
{
|
||
"id": "task-reg-1",
|
||
"name": "v3.0 全模块回归测试",
|
||
"status": "PENDING",
|
||
"plan_id": "plan-regression",
|
||
"assignee": "李四",
|
||
"created_at": now
|
||
},
|
||
{
|
||
"id": "task-req-1",
|
||
"name": "REQ-2001 订单模块需求测试",
|
||
"status": "RUNNING",
|
||
"plan_id": "plan-requirement",
|
||
"assignee": "赵六",
|
||
"created_at": now
|
||
},
|
||
{
|
||
"id": "task-self-1",
|
||
"name": "系统设置模块自测",
|
||
"status": "COMPLETED",
|
||
"plan_id": "plan-selftest",
|
||
"assignee": "王五",
|
||
"created_at": now
|
||
},
|
||
]
|
||
for task_data in mock_tasks:
|
||
db_task = models.TestTask(**task_data)
|
||
db.add(db_task)
|
||
|
||
db.commit()
|
||
print(f"✅ Database seeded: {len(mock_cases)} test cases, {len(mock_tasks)} tasks.")
|
||
db.close()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
seed()
|