Files
cdtestplant_v1/apps/project/schemas/case.py
2025-12-23 10:36:55 +08:00

171 lines
6.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
from apps.project.schemas.testDemand import TestDemandModelOutSchemaOrigin
# 删除schema
class DeleteSchema(Schema):
ids: List[int]
# 测试步骤输出schema
class CaseStepSchema(ModelSchema):
class Meta:
model = CaseStep
fields = ["operation", 'expect', 'result', 'passed', 'case', 'id']
# 测试用例的步骤输出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的标识给前端
class Meta:
model = Case
exclude = ['project', 'round', 'dut', 'design', 'test', 'remark', 'sort']
# 输出case关联问题单
class CaseModelOutSchemaOrigin(ModelSchema):
testStep: List[CaseStepSchema]
testType: str # 用例额外字段用于测试类型FT的标识给前端
# 新增:关联的问题单
problem: Optional[ProblemModelOutSchema] = None
class Meta:
model = Case
exclude = ['project', 'round', 'dut', 'design', 'test', 'remark', 'sort']
# 输出case关联问题单
class CaseModelOutSchema(ModelSchema):
testStep: List[CaseStepSchema]
testType: str # 用例额外字段用于测试类型FT的标识给前端
# 新增:关联的问题单
problem: Optional[ProblemModelOutSchema] = None
# 2025年5月10日新增上级字段
test: Optional[TestDemandModelOutSchemaOrigin] = None
class Meta:
model = Case
exclude = ['project', 'round', 'dut', 'design', 'test', 'remark', 'sort']
# 查询测试项
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]
class Meta:
model = Case
exclude = ['remark', 'sort', 'project', 'round', 'dut', 'design']
# 新增接口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")
# 批量新增测试用例
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] = []
# 由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)
# 替换文本输入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
# 时间替换Schema
class ExetimeReplaceSchema(Schema):
selectRows: List[int] = None
exetime: List[str]