def delete(self, request, *args, **kwargs): """ 删除项目 """ pk = kwargs.get("pk") if pk is None: return response(error=Error.PROJECT_ID_NULL) project = Project.objects.filter(id=pk, is_delete=False).update(is_delete=True) if project == 0: return response(error=Error.PROJECT_OBJECT_NULL) return response()
def get_task(self, request, *args, **kwargs): """ 获得用例数据 /api/interface/v1/task/<pk>/info/ """ pk = kwargs.get("pk") if pk is not None: try: task = TestTask.objects.get(id=pk, is_delete=False) ser = TaskSerializer(instance=task, many=False) except TestTask.DoesNotExist: return response(error=Error.CASE_ID_NULL) return response(data=ser.data)
def update_task(self, request, *args, **kwargs): """ 创建任务 """ cid = request.data.get("id") if cid is None: return response(error=Error.CASE_ID_NULL) task = TestTask.objects.get(pk=cid, is_delete=False) val = TaskValidators(instance=task, data=request.data) if val.is_valid(): val.save() else: return response_fail(val.errors) return response()
def delete_task(self, request, *args, **kwargs): """ 删除用例 /api/interface/v1/task/<pk>/delete/ """ pk = kwargs.get("pk") if pk is None: return response(error=Error.CASE_ID_NULL) task = TestTask.objects.filter(id=pk, is_delete=False).update(is_delete=True) if task == 0: return response(error=Error.CASE_OBJECT_NULL) return response()
def put(self, request, *args, **kwargs): """ 更新一个项目 """ pk = kwargs.get("pk") if pk is None: return response(error=Error.PROJECT_ID_NULL) try: project = Project.objects.get(id=pk, is_delete=False) except Project.DoesNotExist: return response(error=Error.PROJECT_OBJECT_NULL) val = ProjectSaveSerializer(instance=project, data=request.data) if val.is_valid(): val.save() else: return response_fail(val.errors) return response(data=val.data)
def put(self, request, pk): """ 更新一个项目 """ val = ModuleValidators(data=request.data) if val.is_valid() is False: return response_fail(val.errors) try: module = Module.objects.get(id=pk, is_delete=False) module.name = request.data.get('name') module.describe = request.data.get('describe') module.project_id = request.data.get('projectId') module.save() except Module.DoesNotExist: print("aaa", type(Error.MODULE_ID_NULL), Error.MODULE_ID_NULL) return response(error=Error.MODULE_ID_NULL) return response()
def create_task(self, request, *args, **kwargs): """ 创建任务 """ val = TaskValidators(data=request.data) if val.is_valid(): val.save() else: return response_fail(val.errors) return response()
def post(self, request, *args, **kwargs): """ 添加一个项目 """ print("/project/{}/".format(kwargs.get("pk"))) print(type(request.data), request.data) val = ProjectSaveSerializer(data=request.data) if val.is_valid(): val.save() else: return response_fail(val.errors) return response(data=val.data)
def get_task_list(self, request, *args, **kwargs): """ 获得用例数据 /api/interface/v1/task/list/ """ test_case = TestTask.objects.filter(is_delete=False).all() pg = Pagination() page_module = pg.paginate_queryset(queryset=test_case, request=request, view=self) ser = TaskSerializer(instance=page_module, many=True) data = {"total": test_case.count(), "caseList": ser.data} return response(data=data)
def get(self, request, *args, **kwargs): """ 获得所有项目 or 一个项目信息 """ pk = kwargs.get("pk") name = request.query_params.dict()["name"] if pk is None: projects = Project.objects.filter(name__contains=name, is_delete=False).all() pg = Pagination() page_project = pg.paginate_queryset(queryset=projects, request=request, view=self) ser = ProjectQuerySerializer(instance=page_project, many=True) data = { "total": projects.count(), "projectList": ser.data, } return response(data=data) else: try: project = Project.objects.get(id=pk, is_delete=False) project_dict = model_to_dict(project) except Project.DoesNotExist: return response(error=Error.PROJECT_ID_NULL) return response(data=project_dict)
def post(self, request, *args, **kwargs): """ 添加一个模块 """ print("/module/{}/".format(kwargs)) val = ModuleValidators(data=request.data) if val.is_valid() is False: return response_fail(val.errors) name = request.data.get('name') describe = request.data.get('describe') project_id = request.data.get('projectId') project = Project.objects.get(id=project_id) module = Module.objects.create(name=name, describe=describe, project=project) module_dict = model_to_dict(module) return response(data=module_dict)
def get(self, request, *args, **kwargs): """ 模块查询 """ pk = kwargs.get("pk") if pk is not None: print("/module/1/") try: module = Module.objects.get(id=pk, is_delete=False) module_dict = model_to_dict(module) except Module.DoesNotExist: return response(error=Error.PROJECT_ID_NULL) return response(data=module_dict) else: print("/module/?page=1&size=10") modules = Module.objects.filter(is_delete=False).all() pg = Pagination() page_module = pg.paginate_queryset(queryset=modules, request=request, view=self) ser = ModuleSerializer(instance=page_module, many=True) data = { "total": modules.count(), "moduleList": ser.data, } return response(data=data)