2025-04-29 18:09:00 +08:00
|
|
|
|
from pydantic import AliasChoices
|
|
|
|
|
|
from apps.project.models import Case, CaseStep
|
|
|
|
|
|
from ninja import Field, Schema, ModelSchema
|
|
|
|
|
|
from typing import List, Union, Optional
|
|
|
|
|
|
from datetime import date
|
|
|
|
|
|
# 关联问题单
|
|
|
|
|
|
from apps.project.schemas.problem import ProblemModelOutSchema
|
2025-05-10 19:21:24 +08:00
|
|
|
|
from apps.project.schemas.testDemand import TestDemandModelOutSchemaOrigin
|
2025-04-29 18:09:00 +08:00
|
|
|
|
|
|
|
|
|
|
# 删除schema
|
|
|
|
|
|
class DeleteSchema(Schema):
|
|
|
|
|
|
ids: List[int]
|
|
|
|
|
|
|
|
|
|
|
|
# 测试步骤输出schema
|
|
|
|
|
|
class CaseStepSchema(ModelSchema):
|
2025-12-02 18:13:30 +08:00
|
|
|
|
class Meta:
|
2025-04-29 18:09:00 +08:00
|
|
|
|
model = CaseStep
|
2025-12-02 18:13:30 +08:00
|
|
|
|
fields = ["operation", 'expect', 'result', 'passed', 'case', 'id']
|
2025-04-29 18:09:00 +08:00
|
|
|
|
|
|
|
|
|
|
# 测试用例的步骤输出schema,输出isPassed和isExe转换后的
|
|
|
|
|
|
class CaseStepWithTransitionSchema(ModelSchema):
|
|
|
|
|
|
class Meta:
|
|
|
|
|
|
model = CaseStep
|
|
|
|
|
|
fields = ["operation", 'expect', 'result', 'passed', 'case', 'id']
|
|
|
|
|
|
|
|
|
|
|
|
# 输出case:不关联问题单和步骤
|
|
|
|
|
|
class CaseModelOutSchemaWithoutProblem(ModelSchema):
|
|
|
|
|
|
testStep: List[CaseStepWithTransitionSchema]
|
|
|
|
|
|
testType: str # 用例额外字段,用于测试类型FT的标识给前端
|
|
|
|
|
|
|
2025-12-02 18:13:30 +08:00
|
|
|
|
class Meta:
|
2025-04-29 18:09:00 +08:00
|
|
|
|
model = Case
|
2025-12-02 18:13:30 +08:00
|
|
|
|
exclude = ['project', 'round', 'dut', 'design', 'test', 'remark', 'sort']
|
2025-04-29 18:09:00 +08:00
|
|
|
|
|
2025-05-10 19:21:24 +08:00
|
|
|
|
# 输出case:关联问题单
|
|
|
|
|
|
class CaseModelOutSchemaOrigin(ModelSchema):
|
|
|
|
|
|
testStep: List[CaseStepSchema]
|
|
|
|
|
|
testType: str # 用例额外字段,用于测试类型FT的标识给前端
|
|
|
|
|
|
# 新增:关联的问题单
|
|
|
|
|
|
problem: Optional[ProblemModelOutSchema] = None
|
|
|
|
|
|
|
2025-12-02 18:13:30 +08:00
|
|
|
|
class Meta:
|
2025-05-10 19:21:24 +08:00
|
|
|
|
model = Case
|
2025-12-02 18:13:30 +08:00
|
|
|
|
exclude = ['project', 'round', 'dut', 'design', 'test', 'remark', 'sort']
|
2025-05-10 19:21:24 +08:00
|
|
|
|
|
2025-04-29 18:09:00 +08:00
|
|
|
|
# 输出case:关联问题单
|
|
|
|
|
|
class CaseModelOutSchema(ModelSchema):
|
|
|
|
|
|
testStep: List[CaseStepSchema]
|
|
|
|
|
|
testType: str # 用例额外字段,用于测试类型FT的标识给前端
|
|
|
|
|
|
# 新增:关联的问题单
|
|
|
|
|
|
problem: Optional[ProblemModelOutSchema] = None
|
2025-05-10 19:21:24 +08:00
|
|
|
|
# 2025年5月10日新增上级字段
|
|
|
|
|
|
test: Optional[TestDemandModelOutSchemaOrigin] = None
|
2025-04-29 18:09:00 +08:00
|
|
|
|
|
2025-12-02 18:13:30 +08:00
|
|
|
|
class Meta:
|
2025-04-29 18:09:00 +08:00
|
|
|
|
model = Case
|
2025-12-02 18:13:30 +08:00
|
|
|
|
exclude = ['project', 'round', 'dut', 'design', 'test', 'remark', 'sort']
|
2025-04-29 18:09:00 +08:00
|
|
|
|
|
|
|
|
|
|
# 查询测试项
|
|
|
|
|
|
class CaseFilterSchema(Schema):
|
|
|
|
|
|
id: int = Field(None, alias='id')
|
|
|
|
|
|
project_id: int = Field(None, alias='projectId')
|
|
|
|
|
|
round_id: str = Field(None, alias='round')
|
|
|
|
|
|
dut_id: str = Field(None, alias='dut')
|
|
|
|
|
|
design_id: str = Field(None, alias='designDemand')
|
|
|
|
|
|
test_id: str = Field(None, alias='testDemand')
|
|
|
|
|
|
# 其他字段
|
|
|
|
|
|
ident: str = Field(None, alias='ident')
|
|
|
|
|
|
name: str = Field(None, alias='name')
|
|
|
|
|
|
designPerson: str = Field(None, alias='designPerson')
|
|
|
|
|
|
testPerson: str = Field(None, alias='testPerson')
|
|
|
|
|
|
monitorPerson: str = Field(None, alias='monitorPerson')
|
|
|
|
|
|
summarize: str = Field(None, alias='summarize')
|
|
|
|
|
|
|
|
|
|
|
|
# 处理树状结构的schema
|
|
|
|
|
|
class CaseTreeReturnSchema(Schema):
|
|
|
|
|
|
title: str = Field(..., alias='title')
|
|
|
|
|
|
key: str = Field(..., alias='key')
|
|
|
|
|
|
level: str = Field(..., alias='level')
|
|
|
|
|
|
# 3月13日新增字段,让case作为树状尾部节点
|
|
|
|
|
|
isLeaf: bool = Field(True, alias='isLeaf')
|
|
|
|
|
|
# 2024年6月6日新增:用于树图显示
|
|
|
|
|
|
isRelatedProblem: bool = Field(False, alias='isRelatedProblem')
|
|
|
|
|
|
isNotPassed: bool = Field(False, alias='isNotPassed')
|
|
|
|
|
|
|
|
|
|
|
|
class CaseTreeInputSchema(Schema):
|
|
|
|
|
|
# 注意这里有alias
|
|
|
|
|
|
project_id: int = Field(None, alias='projectId')
|
|
|
|
|
|
key: str = Field(None, alias='key')
|
|
|
|
|
|
level: str = Field(None, alias='level')
|
|
|
|
|
|
|
|
|
|
|
|
# 增加测试用例
|
|
|
|
|
|
class CaseCreateOutSchema(ModelSchema):
|
|
|
|
|
|
level: Union[str, int]
|
|
|
|
|
|
|
2025-12-02 18:13:30 +08:00
|
|
|
|
class Meta:
|
2025-04-29 18:09:00 +08:00
|
|
|
|
model = Case
|
2025-12-02 18:13:30 +08:00
|
|
|
|
exclude = ['remark', 'sort', 'project', 'round', 'dut', 'design']
|
2025-04-29 18:09:00 +08:00
|
|
|
|
|
|
|
|
|
|
# 新增接口schema
|
|
|
|
|
|
class CaseInputSchema(Schema):
|
|
|
|
|
|
operation: str = Field(None, alias="operation")
|
|
|
|
|
|
expect: str = Field(None, alias="expect")
|
|
|
|
|
|
result: str = Field(None, alias="result")
|
|
|
|
|
|
passed: str = Field('3', alias="passed")
|
|
|
|
|
|
|
|
|
|
|
|
class CaseCreateInputSchema(Schema):
|
|
|
|
|
|
project_id: int = Field(..., validation_alias=AliasChoices('project_id', 'projectId'),
|
|
|
|
|
|
serialization_alias='projectId')
|
|
|
|
|
|
round_key: str = Field(None, alias="round")
|
|
|
|
|
|
dut_key: str = Field(None, alias="dut")
|
|
|
|
|
|
design_key: str = Field(None, alias="designDemand")
|
|
|
|
|
|
test_key: str = Field(None, alias="testDemand")
|
|
|
|
|
|
# 其他字段
|
|
|
|
|
|
ident: str = Field('', alias='ident')
|
|
|
|
|
|
name: str = Field('', alias='name')
|
|
|
|
|
|
designPerson: str = Field('', alias='designPerson')
|
|
|
|
|
|
testPerson: str = Field('', alias='testPerson')
|
|
|
|
|
|
monitorPerson: str = Field('', alias='monitorPerson')
|
|
|
|
|
|
summarize: str = Field('', alias='summarize')
|
|
|
|
|
|
initialization: str = Field('', alias='initialization')
|
|
|
|
|
|
premise: str = Field('', alias='premise')
|
|
|
|
|
|
testStep: List[CaseInputSchema]
|
|
|
|
|
|
# 新增执行时间字段
|
|
|
|
|
|
exe_time: date = Field(None, alias='exe_time')
|
|
|
|
|
|
# 新增时序图字段
|
|
|
|
|
|
timing_diagram: str = Field("", alias="timing_diagram")
|
|
|
|
|
|
|
2025-12-19 18:08:19 +08:00
|
|
|
|
# 批量新增测试用例
|
|
|
|
|
|
class OneCaseBatchCreateSchema(Schema):
|
|
|
|
|
|
parent_key: str
|
|
|
|
|
|
name: str
|
|
|
|
|
|
summarize: Optional[str] = ""
|
|
|
|
|
|
initialization: Optional[str] = ""
|
|
|
|
|
|
premise: Optional[str] = ""
|
|
|
|
|
|
sequence: Optional[str] = "" # 时序图
|
|
|
|
|
|
test_step: str
|
|
|
|
|
|
|
|
|
|
|
|
class BatchCreateCaseInputSchema(Schema):
|
|
|
|
|
|
project_id: int = Field(..., validation_alias=AliasChoices('project_id', 'projectId'))
|
|
|
|
|
|
cases: List[OneCaseBatchCreateSchema] = []
|
|
|
|
|
|
|
2025-04-29 18:09:00 +08:00
|
|
|
|
# 由demand创建case的输入Schema
|
|
|
|
|
|
class DemandNodeSchema(Schema):
|
|
|
|
|
|
project_id: int
|
|
|
|
|
|
level: int = Field(3, gt=0)
|
|
|
|
|
|
isLeaf: bool = False
|
|
|
|
|
|
key: str = Field(None, alias='nodekey')
|
|
|
|
|
|
title: str = Field(None)
|
2025-05-10 19:21:24 +08:00
|
|
|
|
|
|
|
|
|
|
# 替换文本输入Schema
|
|
|
|
|
|
class ReplaceCaseSchema(Schema):
|
|
|
|
|
|
project_id: int
|
|
|
|
|
|
round_key: str
|
|
|
|
|
|
originText: str
|
|
|
|
|
|
replaceText: str
|
|
|
|
|
|
selectRows: List[int]
|
|
|
|
|
|
selectColumn: List[str]
|
|
|
|
|
|
|
|
|
|
|
|
# 人员替换Schema
|
|
|
|
|
|
class PersonReplaceSchema(Schema):
|
|
|
|
|
|
selectRows: List[int] = None
|
|
|
|
|
|
designPerson: str
|
|
|
|
|
|
testPerson: str
|
|
|
|
|
|
monitorPerson: str
|
|
|
|
|
|
|
2025-05-28 18:44:25 +08:00
|
|
|
|
# 时间替换Schema
|
2025-05-10 19:21:24 +08:00
|
|
|
|
class ExetimeReplaceSchema(Schema):
|
|
|
|
|
|
selectRows: List[int] = None
|
2025-12-23 10:36:55 +08:00
|
|
|
|
exetime: List[str]
|