增加批量增加用例、测试项、设计需求功能
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,8 +8,9 @@ from utils.chen_pagination import MyPagination
|
||||
from django.db import transaction
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db.models.functions import Replace
|
||||
from django.db.models import Q, F, Value
|
||||
from django.db.models import F, Value
|
||||
from typing import List
|
||||
from django.utils import timezone
|
||||
from utils.chen_response import ChenResponse
|
||||
from utils.chen_crud import multi_delete_case
|
||||
from apps.project.models import Design, Dut, Round, TestDemand, Case, CaseStep, Project, Problem
|
||||
@@ -20,8 +21,9 @@ from utils.util import get_testType
|
||||
from utils.codes import HTTP_INDEX_ERROR, HTTP_EXISTS_CASES
|
||||
from apps.project.tools.copyCase import case_move_to_test, case_copy_to_test, case_to_case_copy_or_move
|
||||
from utils.smallTools.interfaceTools import conditionNoneToBlank
|
||||
from apps.project.tool.batchTools import parse_case_content_string
|
||||
# 导入case的schema
|
||||
from apps.project.schemas.case import CaseModelOutSchemaWithoutProblem
|
||||
from apps.project.schemas.case import CaseModelOutSchemaWithoutProblem, BatchCreateCaseInputSchema
|
||||
|
||||
@api_controller("/project", auth=JWTAuth(), permissions=[IsAuthenticated], tags=['测试用例接口'])
|
||||
class CaseController(ControllerBase):
|
||||
@@ -120,7 +122,7 @@ class CaseController(ControllerBase):
|
||||
@transaction.atomic
|
||||
def create_case(self, payload: CaseCreateInputSchema):
|
||||
asert_dict = payload.dict(exclude_none=True)
|
||||
# 构造design_key
|
||||
# 构造demand_key
|
||||
test_whole_key = "".join(
|
||||
[payload.round_key, "-", payload.dut_key, '-', payload.design_key, '-', payload.test_key])
|
||||
# 查询当前key应该为多少
|
||||
@@ -157,6 +159,52 @@ class CaseController(ControllerBase):
|
||||
CaseStep.objects.bulk_create(data_list) # type:ignore
|
||||
return qs
|
||||
|
||||
# 批量新增用例
|
||||
@route.post("/case/multi_save", url_name="case-batch-create")
|
||||
@transaction.atomic
|
||||
def multi_case_save(self, payload: BatchCreateCaseInputSchema):
|
||||
project_obj = get_object_or_404(Project, id=payload.project_id)
|
||||
user_name = self.context.request.user.name
|
||||
keys = []
|
||||
demands = project_obj.ptField.all() # 当前项目所有测试项
|
||||
for case_data in payload.cases:
|
||||
# 解析放在前面防止出错
|
||||
stepsOrErrorResponse = parse_case_content_string(case_data.test_step)
|
||||
if isinstance(stepsOrErrorResponse, ChenResponse):
|
||||
return stepsOrErrorResponse
|
||||
# 查询当前测试项下case数量,以设置case的key
|
||||
demand_key = case_data.parent_key
|
||||
demand_obj = demands.filter(key=demand_key).first()
|
||||
case_count = demand_obj.tcField.count()
|
||||
key_string = ''.join([demand_key, "-", str(case_count)])
|
||||
keys.append(key_string)
|
||||
case_dict = {
|
||||
"ident": demand_obj.ident,
|
||||
"name": case_data.name,
|
||||
"key": key_string,
|
||||
"initialization": case_data.initialization,
|
||||
"premise": case_data.premise,
|
||||
"summarize": case_data.summarize,
|
||||
"designPerson": user_name,
|
||||
"testPerson": user_name,
|
||||
"monitorPerson": user_name,
|
||||
"project": project_obj,
|
||||
"round": demand_obj.round,
|
||||
"dut": demand_obj.dut,
|
||||
"design": demand_obj.design,
|
||||
"test": demand_obj,
|
||||
"exe_time": timezone.now(),
|
||||
"timing_diagram": case_data.sequence,
|
||||
"title": case_data.name
|
||||
}
|
||||
case_new_obj = Case.objects.create(**case_dict)
|
||||
case_step_list = []
|
||||
for step in stepsOrErrorResponse:
|
||||
case_step_list.append(CaseStep(**{"case": case_new_obj, "operation": step['operation'],
|
||||
"expect": step['expect']}))
|
||||
CaseStep.objects.bulk_create(case_step_list)
|
||||
return ChenResponse(code=60000, status=200, data=keys, message='成功录入用例')
|
||||
|
||||
# 更新测试用例
|
||||
@route.put("/case/update/{id}", response=CaseCreateOutSchema, url_name="case-update")
|
||||
@transaction.atomic
|
||||
@@ -283,7 +331,6 @@ class CaseController(ControllerBase):
|
||||
@route.post("/case/replace/", url_name='case-replace')
|
||||
@transaction.atomic
|
||||
def replace_case_step_content(self, payload: ReplaceCaseSchema):
|
||||
print(payload)
|
||||
# 1.首先查询项目
|
||||
project_obj: Project = get_object_or_404(Project, id=payload.project_id)
|
||||
# 2.查询[所有轮次]的selectRows的id
|
||||
|
||||
@@ -20,6 +20,7 @@ from apps.project.schemas.design import DeleteSchema, DesignFilterSchema, Design
|
||||
ReplaceDesignContentSchema
|
||||
from apps.project.tools.delete_change_key import design_delete_sub_node_key
|
||||
from utils.smallTools.interfaceTools import conditionNoneToBlank
|
||||
from apps.project.tools.auto_create_data import auto_create_renji
|
||||
|
||||
@api_controller("/project", auth=JWTAuth(), permissions=[IsAuthenticated], tags=['设计需求数据'])
|
||||
class DesignController(ControllerBase):
|
||||
@@ -162,7 +163,7 @@ class DesignController(ControllerBase):
|
||||
design_delete_sub_node_key(single_qs)
|
||||
return ChenResponse(message="设计需求删除成功!")
|
||||
|
||||
# 给复制功能级联选择器查询所有的设计需求
|
||||
# 给复制功能级联选择器查询所有的设计需求【这是查项目所有的设计需求】
|
||||
@route.get("/designDemand/getRelatedDesign", url_name='dut-relatedDesign')
|
||||
def getRelatedDesign(self, id: int):
|
||||
project_qs = get_object_or_404(Project, id=id)
|
||||
@@ -196,3 +197,15 @@ class DesignController(ControllerBase):
|
||||
# 4.提交更新
|
||||
replace_count = design_qs.update(**replace_kwargs)
|
||||
return {'count': replace_count}
|
||||
|
||||
# 点击生成人机交互界面测试-注意必须要有界面的软件
|
||||
@route.get("/create_renji/", url_name='renji')
|
||||
@transaction.atomic
|
||||
def create_rj(self, round_id: int, project_id: int):
|
||||
user_name = self.context.request.user.name # 获取当前用户名
|
||||
project_obj: Project = get_object_or_404(Project, id=project_id)
|
||||
dut_qs = Dut.objects.filter(round__key=round_id, project=project_obj, type='XQ').first()
|
||||
if dut_qs:
|
||||
auto_create_renji(user_name, dut_qs, project_obj)
|
||||
return ChenResponse(status=200, message='自动生成人机界面交互测试成功!', data=dut_qs.key)
|
||||
return ChenResponse(status=402, message='您还未录入需求规格说明文档,请录入后再试')
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from multiprocessing.spawn import old_main_modules
|
||||
|
||||
from ninja_extra import api_controller, ControllerBase, route
|
||||
from ninja import Query
|
||||
from ninja_jwt.authentication import JWTAuth
|
||||
@@ -17,13 +19,15 @@ from apps.project.models import Design, Dut, Round, TestDemand, TestDemandConten
|
||||
from apps.project.schemas.testDemand import DeleteSchema, TestDemandModelOutSchema, TestDemandFilterSchema, \
|
||||
TestDemandTreeReturnSchema, TestDemandTreeInputSchema, TestDemandCreateOutSchema, \
|
||||
TestDemandCreateInputSchema, ReplaceDemandContentSchema, PriorityReplaceSchema, \
|
||||
TestDemandRelatedSchema, TestDemandExistRelatedSchema, DemandCopyToDesignSchema
|
||||
TestDemandRelatedSchema, TestDemandExistRelatedSchema, DemandCopyToDesignSchema, \
|
||||
TestDemandMultiCreateInputSchema
|
||||
# 导入ORM
|
||||
from apps.project.models import Project
|
||||
# 导入工具
|
||||
from apps.project.tools.copyDemand import demand_copy_to_design
|
||||
from apps.project.tools.delete_change_key import demand_delete_sub_node_key
|
||||
from utils.smallTools.interfaceTools import conditionNoneToBlank
|
||||
from apps.project.tool.batchTools import parse_test_content_string
|
||||
|
||||
@api_controller("/project", auth=JWTAuth(), permissions=[IsAuthenticated], tags=['测试项接口'])
|
||||
class TestDemandController(ControllerBase):
|
||||
@@ -134,13 +138,13 @@ class TestDemandController(ControllerBase):
|
||||
asert_dict.pop("dut_key")
|
||||
asert_dict.pop("design_key")
|
||||
asert_dict.pop("testContent")
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# 创建测试项 - 以及子项/子项步骤
|
||||
qs = TestDemand.objects.create(**asert_dict)
|
||||
for item in payload.dict()['testContent']:
|
||||
content_obj = TestDemandContent.objects.create(
|
||||
testDemand=qs,
|
||||
subName=item['subName']
|
||||
subName=item['subName'],
|
||||
subDescription=item['subDescription']
|
||||
)
|
||||
TestDemandContentStep.objects.bulk_create([
|
||||
TestDemandContentStep(
|
||||
@@ -151,6 +155,69 @@ class TestDemandController(ControllerBase):
|
||||
])
|
||||
return qs
|
||||
|
||||
# 批量新增测试项
|
||||
@route.post("/testDemand/multi_save", url_name="testDemand-multi-create")
|
||||
@transaction.atomic
|
||||
def create_multi_test_demand(self, payload: TestDemandMultiCreateInputSchema):
|
||||
# 1.首先判断测试项标识是否重复
|
||||
project_qs = Project.objects.filter(id=payload.project_id).first()
|
||||
designs = project_qs.psField.all()
|
||||
## 给返回response的data数据以便前端更新树状目录
|
||||
keys = []
|
||||
## 遍历payload.demands数组
|
||||
for index, demandOne in enumerate(payload.demands):
|
||||
if demandOne.ident and project_qs:
|
||||
old_obj = project_qs.ptField.filter(ident=demandOne.ident).first()
|
||||
if old_obj and old_obj.testType == demandOne.testType:
|
||||
message_temp = f"第{index}个测试项标识重复,请修改"
|
||||
return ChenResponse(status=200, code=500101, data=index, message=message_temp)
|
||||
# 标识不重复就开始录入了
|
||||
for index, demand in enumerate(payload.demands):
|
||||
create_sub_demands = parse_test_content_string(demand.testContent)
|
||||
if isinstance(create_sub_demands, ChenResponse):
|
||||
return create_sub_demands
|
||||
else:
|
||||
# 这说明解析成功了
|
||||
# 首先查询所属design、dut、round,方便新增
|
||||
design_obj: Design = designs.filter(key=demand.parent_key).first() # 因为前端限制必然有
|
||||
dut_obj = design_obj.dut
|
||||
round_obj = design_obj.round
|
||||
test_demand_count = TestDemand.objects.filter(project=project_qs,
|
||||
design=design_obj).count()
|
||||
key_string = ''.join([design_obj.key, "-", str(test_demand_count)])
|
||||
keys.append(key_string)
|
||||
create_demand_dict = {
|
||||
'ident': demand.ident,
|
||||
'name': demand.name,
|
||||
'adequacy': demand.adequacy,
|
||||
'priority': demand.priority,
|
||||
'testType': demand.testType,
|
||||
'testMethod': demand.testMethod,
|
||||
'title': demand.name,
|
||||
'key': key_string,
|
||||
'project': project_qs,
|
||||
'round': round_obj,
|
||||
'dut': dut_obj,
|
||||
'design': design_obj,
|
||||
'testDesciption': demand.testDesciption
|
||||
}
|
||||
demand_created = TestDemand.objects.create(**create_demand_dict)
|
||||
# 录入测试子项
|
||||
for sub in create_sub_demands:
|
||||
content_obj = TestDemandContent.objects.create(
|
||||
testDemand=demand_created,
|
||||
subName=sub['subName'],
|
||||
subDescription=sub['subDescription']
|
||||
)
|
||||
TestDemandContentStep.objects.bulk_create([
|
||||
TestDemandContentStep(
|
||||
testDemandContent=content_obj,
|
||||
**step.dict() if not isinstance(step, dict) else step
|
||||
)
|
||||
for step in sub['subStep']
|
||||
])
|
||||
return ChenResponse(code=200991, status=200, data=keys, message='成功录入')
|
||||
|
||||
# 更新测试项
|
||||
@route.put("/testDemand/update/{id}", response=TestDemandCreateOutSchema, url_name="testDemand-update")
|
||||
@transaction.atomic
|
||||
@@ -184,7 +251,8 @@ class TestDemandController(ControllerBase):
|
||||
if item['subName']:
|
||||
content_obj = TestDemandContent.objects.create(
|
||||
testDemand=testDemand_qs,
|
||||
subName=item["subName"]
|
||||
subName=item["subName"],
|
||||
subDescription=item["subDescription"]
|
||||
)
|
||||
TestDemandContentStep.objects.bulk_create([
|
||||
TestDemandContentStep(
|
||||
@@ -224,7 +292,7 @@ class TestDemandController(ControllerBase):
|
||||
demand_delete_sub_node_key(single_qs) # 删除后需重排子节点
|
||||
return ChenResponse(message="测试需求删除成功!")
|
||||
|
||||
# 查询一个项目的所有测试项
|
||||
# 查询一个项目的所有测试项【当前轮次】
|
||||
@route.get("/testDemand/getRelatedTestDemand", url_name="testDemand-getRelatedTestDemand")
|
||||
@transaction.atomic
|
||||
def getRelatedTestDemand(self, id: int, round: str):
|
||||
@@ -236,7 +304,7 @@ class TestDemandController(ControllerBase):
|
||||
for design in designs:
|
||||
design_dict = {'label': design.name, 'value': design.id, 'children': []}
|
||||
for test_item in design.dtField.all():
|
||||
test_item_dict = {'label': test_item.name, 'value': test_item.id}
|
||||
test_item_dict = {'label': test_item.name, 'value': test_item.id, 'key': test_item.key}
|
||||
design_dict['children'].append(test_item_dict)
|
||||
data_list.append(design_dict)
|
||||
return ChenResponse(message='获取成功', data=data_list)
|
||||
|
||||
Reference in New Issue
Block a user