Skip to content

Commit

Permalink
👷 添加部分模块注释
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiaolulu committed Feb 8, 2024
1 parent 4bb160c commit b2aad94
Show file tree
Hide file tree
Showing 11 changed files with 12,243 additions and 42 deletions.
50 changes: 27 additions & 23 deletions backend/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion backend/api/dao/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ class ReportDao:
|---📃step-detail 测试场景下包含的步骤执行接口详情信息
"""

@classmethod
def detail_step_list(cls, get_queryset, report_id, name: str = ""):
if not report_id:
raise Exception("缺少必要参数报告id❌ ")
else:
try:
queryset = get_queryset.filter(report_id=report_id)

if name:
queryset = queryset.filter(name=name)

return queryset

except Exception as err:
logger.debug(
f"🏓获取测试报告数据失败 -> {err}"
)
raise Exception(f"获取测试报告数据失败❌ {err}")

@staticmethod
def parser_report_main(plan_name, result_list):
"""
Expand Down Expand Up @@ -101,9 +120,10 @@ def create_detail_step(class_item, model):
Exception: 创建报告测试详情步骤失败时抛出异常
"""
try:
for case_item in class_item.get('cases', []):
for index, case_item in enumerate(class_item.get('cases', [])):

DetailStep.objects.create(
sort=(index + 1),
detail=Detail.objects.get(id=model.id),
name=case_item.get('name', 'Demo'),
log_data=case_item.get('log_data', []),
Expand Down
11 changes: 10 additions & 1 deletion backend/api/filters/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import django_filters.rest_framework as filters
from api.models.report import Main
from api.models.report import Main, Detail


class ReportFilter(filters.FilterSet):
Expand All @@ -9,3 +9,12 @@ class ReportFilter(filters.FilterSet):
class Meta:
model = Main
fields = ["name"]


class ReportDetailFilter(filters.FilterSet):

name = filters.CharFilter(field_name='name', help_text='按用例名模糊查询', lookup_expr='icontains')

class Meta:
model = Detail
fields = ["name"]
1 change: 1 addition & 0 deletions backend/api/models/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class DetailStep(Model):
* extras: 提取参数
"""
id = AutoField(primary_key=True)
sort = CharField(max_length=200, null=True, blank=True, verbose_name=_('DetailStep sort'))
detail = ForeignKey(Detail, null=True, on_delete=SET_NULL, related_name='steps', verbose_name=_('DetailStep Step'))
name = CharField(max_length=50, null=True, blank=True, verbose_name=_('DetailStep Name'))
log_data = TextField(verbose_name=_('DetailStep LogData'), null=False, default=None)
Expand Down
40 changes: 35 additions & 5 deletions backend/api/service/report.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters
from rest_framework import (
filters,
mixins,
status,
viewsets
)
from rest_framework.permissions import IsAuthenticated
from api.filters.report import ReportFilter
from rest_framework.response import Response
from api.dao.report import ReportDao
from api.filters.report import (
ReportFilter
)
from api.mixins.magic import (
MagicRetrieveApi,
MagicListAPI
)
from api.models.report import (
Expand All @@ -16,12 +24,34 @@
)


class ReportDetailView(MagicRetrieveApi):
class ReportDetailView(mixins.ListModelMixin, viewsets.GenericViewSet):

queryset = Detail.objects.all()
serializer_class = ReportDetailSerializers
queryset = Detail.objects
permission_classes = [IsAuthenticated]

def list(self, request, *args, **kwargs):
context = {
"request": request,
}
serializer = ReportDetailSerializers(data=request.query_params, context=context)
if serializer.is_valid():
report_id = request.query_params.get("id")
name = request.query_params.get("name")

queryset = self.get_queryset()
queryset = ReportDao.detail_step_list(queryset, report_id, name)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)

serializer = self.get_serializer(queryset, many=True)

return Response(serializer.data)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class ReportListViewSet(MagicListAPI):

Expand Down
7 changes: 3 additions & 4 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
include
)
from rest_framework.routers import DefaultRouter

from api.service.https import (
ApiFastView,
TreeView,
Expand Down Expand Up @@ -98,9 +99,7 @@
path('case/run', RunCaseView.as_view()),
path('case/delete/<int:pk>', DelCaseView.as_view()),
path('case/detail/<int:pk>', CaseDetailView.as_view()),
path("case/list", CaseListView.as_view({
'get': 'list'
})),
path("case/list", CaseListView.as_view({'get': 'list'})),

# 测试计划
path("plan/SaveOrUpdate/<int:pk>", SaveOrUpdatePlanView.as_view()),
Expand All @@ -111,7 +110,7 @@
path("plan/list", PlanListViewSet.as_view()),

# 测试报告
path("report/detail/<int:pk>", ReportDetailView.as_view()),
path("report/detail", ReportDetailView.as_view({'get': 'list'})),
path("report/list", ReportListViewSet.as_view())
]

Expand Down
Loading

0 comments on commit b2aad94

Please sign in to comment.