def post(self, request): """ 删除域名 :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result try: Project.objects.get(id=data["project_id"]) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) try: for j in data["ids"]: obj = GlobalHost.objects.filter(id=j) if obj: obj.delete() name = obj[0].name record_dynamic(project=data["project_id"], _type="删除", operationObject="域名", user=request.user.pk, data=name) return JsonResponse(code_msg=GlobalStatusCode.success()) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def del_history(request): """ 删除请求历史 project_id 项目ID api_id 接口ID history_id 请求历史ID :return: """ project_id = request.POST.get("project_id") api_id = request.POST.get("api_id") history_id = request.POST.get("history_id") if not project_id.isdecimal() or not api_id.isdecimal( ) or not history_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = ApiInfo.objects.filter(id=api_id, project=project_id) if obi: obm = APIRequestHistory.objects.filter(id=history_id, apiInfo=api_id) if obm: obm.delete() api_record = ApiOperationHistory( apiInfo=ApiInfo.objects.get(id=api_id), user=User.objects.get(id=request.user.pk), description="删除请求历史记录") api_record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.history_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.api_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def post(self, request): """ 添加Host :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result try: obj = Project.objects.get(id=data["project_id"]) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) obi = GlobalHost.objects.filter(name=data["name"], project=data["project_id"]) if obi: return JsonResponse(code_msg=GlobalStatusCode.name_repetition()) else: serializer = GlobalHostSerializer(data=data) with transaction.atomic(): if serializer.is_valid(): # 外键project_id serializer.save(project=obj) # 记录动态 record_dynamic(project=data["project_id"], _type="添加", operationObject="域名", user=request.user.pk, data=data["name"]) return JsonResponse( data={"host_id": serializer.data.get("id")}, code_msg=GlobalStatusCode.success()) return JsonResponse(code_msg=GlobalStatusCode.fail())
def project_member(request): """ 获取成员信息 project_id 项目ID :return: """ try: page_size = int(request.GET.get('page_size', 20)) page = int(request.GET.get('page', 1)) except (TypeError, ValueError): return JsonResponse(code_msg=GlobalStatusCode.page_not_int()) project_id = request.GET.get('project_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = ProjectMember.objects.filter(project=project_id).order_by('id') paginator = Paginator(obi, page_size) # paginator对象 total = paginator.num_pages # 总页数 try: obm = paginator.page(page) except PageNotAnInteger: obm = paginator.page(1) except EmptyPage: obm = paginator.page(paginator.num_pages) serialize = ProjectMemberSerializer(obm, many=True) return JsonResponse(data={ 'data': serialize.data, 'page': page, 'total': total }, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def post(self, request): """ 修改项目 :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result # 查找项目是否存在 try: obj = Project.objects.get(id=data["project_id"]) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) # 查找是否相同名称的项目 obi = Project.objects.filter(name=data["name"]).exclude( id=data["project_id"]) if len(obi) == 0: serializer = ProjectDeserializer(data=data) with transaction.atomic(): if serializer.is_valid(): # 修改项目 serializer.update(instance=obj, validated_data=data) # 记录动态 record_dynamic(project=data["project_id"], _type="修改", operationObject="项目", user=request.user.pk, data=data["name"]) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.fail()) else: return JsonResponse(code_msg=GlobalStatusCode.name_repetition())
def dynamic(request): """ 获取动态数量 project_id 项目ID :return: """ try: page_size = int(request.GET.get("page_size", 20)) page = int(request.GET.get("page", 1)) except (TypeError, ValueError): return JsonResponse(code_msg=GlobalStatusCode.page_not_int()) project_id = request.GET.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obi = Project.objects.filter(id=project_id) if obi: obj = ProjectDynamic.objects.filter(project=project_id).order_by("-time") paginator = Paginator(obj, page_size) # paginator对象 total = paginator.num_pages # 总页数 try: obm = paginator.page(page) except PageNotAnInteger: obm = paginator.page(1) except EmptyPage: obm = paginator.page(paginator.num_pages) serialize = ProjectDynamicSerializer(obm, many=True) return JsonResponse(data={"data": serialize.data, "page": page, "total": total }, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def enable_host(request): """ 启用host project_id 项目ID host_id 地址ID :return: """ project_id = request.POST.get('project_id') host_id = request.POST.get('host_id') if not project_id.isdecimal() or not host_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = GlobalHost.objects.filter(id=host_id, project=project_id) if obi: obi.update(status=True) record = ProjectDynamic(project=Project.objects.get(id=project_id), type='启用', operationObject='HOST', user=User.objects.get(id=request.user.pk), description='启用HOST“%s”' % obi[0].name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.host_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def del_api(request): """ 删除接口 project_id 项目ID api_ids 接口ID列表 :return: """ project_id = request.POST.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) ids = request.POST.get("api_ids") id_list = ids.split(",") for i in id_list: if not i.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: for j in id_list: obi = ApiInfo.objects.filter(id=j, project=project_id) if len(obi) != 0: name = obi[0].name obi.delete() record_dynamic(project_id, "删除", "接口", "删除接口“%s”" % name) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def update_group(request): """ 修改接口所属分组 project_id 项目ID api_ids 接口ID列表 first_group_id 一级分组ID second_group_id 二级分组ID :return: """ project_id = request.POST.get("project_id") ids = request.POST.get("api_ids") id_list = ids.split(",") first_group_id = request.POST.get("first_group_id") second_group_id = request.POST.get("second_group_id") if not project_id.isdecimal() or not first_group_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: api_first_group = ApiGroupLevelFirst.objects.filter(id=first_group_id) if api_first_group: if first_group_id and second_group_id: if not second_group_id.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) api_second_group = ApiGroupLevelSecond.objects.filter( id=second_group_id) if api_second_group: for i in id_list: if not i.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) for j in id_list: ApiInfo.objects.filter( id=j, project=project_id).update( apiGroupLevelFirst=ApiGroupLevelFirst.objects. get(id=first_group_id), apiGroupLevelSecond=ApiGroupLevelSecond. objects.get(id=second_group_id)) else: return JsonResponse( code_msg=GlobalStatusCode.group_not_exist()) elif first_group_id and second_group_id == "": for i in id_list: if not i.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) for j in id_list: ApiInfo.objects.filter(id=j, project=project_id).update( apiGroupLevelFirst=ApiGroupLevelFirst.objects.get( id=first_group_id)) else: return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) record_dynamic(project_id, "修改", "接口", "修改接口分组,列表“%s”" % id_list) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.group_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def operation_history(request): """ 接口操作历史 project_id 项目ID api_id 接口ID page_size 条数 page 页码 :return: """ try: page_size = int(request.GET.get("page_size", 20)) page = int(request.GET.get("page", 1)) except (TypeError, ValueError): return JsonResponse(code_msg=GlobalStatusCode.page_not_int()) project_id = request.GET.get("project_id") api_id = request.GET.get("api_id") if not project_id.isdecimal() or not api_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) obj = Project.objects.filter(id=project_id) if obj: obi = ApiInfo.objects.filter(id=api_id, project=project_id) if obi: obn = ApiOperationHistory.objects.filter( apiInfo=api_id).order_by("-time") paginator = Paginator(obn, page_size) # paginator对象 total = paginator.num_pages # 总页数 try: obm = paginator.page(page) except PageNotAnInteger: obm = paginator.page(1) except EmptyPage: obm = paginator.page(paginator.num_pages) serialize = ApiOperationHistorySerializer(obm, many=True) return JsonResponse(data={ "data": serialize.data, "page": page, "total": total }, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.api_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def project_info(request): """ 获取项目详情 project_id 项目id :return: """ project_id = request.GET.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) try: obj = Project.objects.get(id=project_id) serialize = ProjectSerializer(obj) return JsonResponse(data=serialize.data, code_msg=GlobalStatusCode.success()) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def del_email(request): """ 删除邮箱配置 :param request: :return: """ project_id = request.POST.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.success()) obi = Project.objects.filter(id=project_id) if obi: AutomationReportSendConfig.objects.filter(project=project_id).delete() record_dynamic(project_id, "删除", "邮箱", "删除邮箱配置") return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def post(self, request): """ 删除项目 :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result try: for j in data["ids"]: obj = Project.objects.filter(id=j) obj.delete() return JsonResponse(code_msg=GlobalStatusCode.success()) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def get_email(request): """ 获取邮箱配置 :param request: :return: """ project_id = request.GET.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.success()) obi = Project.objects.filter(id=project_id) if obi: data = AutomationReportSendConfigSerializer( AutomationReportSendConfig.objects.filter(project=project_id), many=True).data return JsonResponse(code_msg=GlobalStatusCode.success(), data=data) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def get(self, request): """ 获取项目详情 :param request: :return: """ project_id = request.GET.get("project_id") result = self.parameter_check(project_id) if result: return result # 查找项目是否存在 try: obj = Project.objects.get(id=project_id) except ObjectDoesNotExist: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) serialize = ProjectSerializer(obj) return JsonResponse(data=serialize.data, code_msg=GlobalStatusCode.success())
def add_group(request): """ 添加接口分组 project_id 项目ID name 名称 first_group_id 一级分组ID :return: """ project_id = request.POST.get("project_id") name = request.POST.get("name") first_group_id = request.POST.get("first_group_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: # 添加二级分组名称 if first_group_id: if not first_group_id.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) obi = ApiGroupLevelFirst.objects.filter(id=first_group_id, project=project_id) if obi: obi = ApiGroupLevelSecond( apiGroupLevelFirst=ApiGroupLevelFirst.objects.get( id=first_group_id), name=name) obi.save() else: return JsonResponse( code_msg=GlobalStatusCode.group_not_exist()) # 添加一级分组名称 else: obi = ApiGroupLevelFirst( project=Project.objects.get(id=project_id), name=name) obi.save() record_dynamic(project=project_id, _type="新增", operationObject="接口分组", user=request.user.pk, data="新增接口分组“%s”" % obi.name) return JsonResponse(data={"group_id": obi.pk}, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def update_name_group(request): """ 修改接口分组名称 project_id 项目ID name 名称 first_group_id 一级分组ID second_group_id 二级分组id :return: """ project_id = request.POST.get("project_id") name = request.POST.get("name") first_group_id = request.POST.get("first_group_id") second_group_id = request.POST.get("second_group_id") if not project_id.isdecimal() or not first_group_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = ApiGroupLevelFirst.objects.filter(id=first_group_id, project=project_id) if obi: # 修改二级分组名称 if second_group_id: if not second_group_id.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) obm = ApiGroupLevelSecond.objects.filter( id=second_group_id, apiGroupLevelFirst=first_group_id) if obm: obm.update(name=name) else: return JsonResponse( code_msg=GlobalStatusCode.group_not_exist()) # 修改一级分组名称 else: obi.update(name=name) record_dynamic(project=project_id, _type="修改", operationObject="接口分组", user=request.user.pk, data="修改接口分组“%s”" % name) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.group_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def del_group(request): """ 删除接口分组 project_id 项目ID first_group_id 一级分组id second_group_id 二级分组id :return: """ project_id = request.POST.get("project_id") first_group_id = request.POST.get("first_group_id") if not project_id.isdecimal() or not first_group_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) second_group_id = request.POST.get("second_group_id") obj = Project.objects.filter(id=project_id) if obj: obi = ApiGroupLevelFirst.objects.filter(id=first_group_id, project=project_id) if obi: name = obi[0].name # 删除二级分组 if second_group_id: if not second_group_id.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) obi = ApiGroupLevelSecond.objects.filter( id=second_group_id, apiGroupLevelFirst=first_group_id) if obi: obi.delete() else: return JsonResponse( code_msg=GlobalStatusCode.group_not_exist()) else: obi.delete() record_dynamic(project=project_id, _type="删除", operationObject="接口分组", user=request.user.pk, data="删除接口分组“%s”" % name) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.group_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def update_project(request): """ 修改项目 project_id: 项目唯一id name: 项目名称 v: 项目版本 type: 项目类型 description: 项目描述 :return: """ project_id = request.POST.get('project_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get('name') version = request.POST.get('v') _type = request.POST.get('type') description = request.POST.get('description') if _type in ['Web', 'App']: obj = Project.objects.filter(id=project_id) if obj: obi = Project.objects.filter(name=name).exclude(id=project_id) if len(obi) == 0: obj.update(name=name, version=version, type=_type, description=description, user=User.objects.get(id=request.user.pk)) record = ProjectDynamic( project=Project.objects.get(id=project_id), type='修改', operationObject='项目', user=User.objects.get(id=request.user.pk), description='修改项目“%s”' % name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong())
def download(request): """ 获取Api下载文档路径 project_id 项目ID :param request: :return: """ project_id = request.GET.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: data = ApiInfoDocSerializer( ApiGroupLevelFirst.objects.filter(project=project_id), many=True).data url = Write().write_api(str(obj[0]), data) return JsonResponse(code_msg=GlobalStatusCode.success(), data=url) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def lead_swagger(request): """ 导入swagger接口信息 :param request: :return: """ project_id = request.POST.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) url = request.POST.get("url") obi = Project.objects.filter(id=project_id) if obi: try: swagger_api(url, project_id, request.user) return JsonResponse(code_msg=GlobalStatusCode.success()) except: return JsonResponse(code_msg=GlobalStatusCode.fail()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def group(request): """ 接口分组 project_id 项目ID :return: """ project_id = request.GET.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = ApiGroupLevelFirst.objects.filter( project=project_id).order_by("id") serialize = ApiGroupLevelFirstSerializer(obi, many=True) return JsonResponse(data=serialize.data, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def update_project(request): """ 修改项目 project_id: 项目唯一id name: 项目名称 v: 项目版本 type: 项目类型 description: 项目描述 :return: """ project_id = request.POST.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get("name") version = request.POST.get("v") _type = request.POST.get("type") description = request.POST.get("description") if _type in ["Web", "App"]: obj = Project.objects.filter(id=project_id) if obj: obi = Project.objects.filter(name=name).exclude(id=project_id) if len(obi) == 0: obj.update(name=name, version=version, type=_type, description=description, user=User.objects.get(id=request.user.pk)) record = ProjectDynamic( project=Project.objects.get(id=project_id), type="修改", operationObject="项目", user=User.objects.get(id=request.user.pk), description="修改项目“%s”" % name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong())
def add_group(request): """ 添加接口分组 project_id 项目ID name 名称 first_group_id 一级分组ID :return: """ project_id = request.POST.get('project_id') name = request.POST.get('name') first_group_id = request.POST.get('first_group_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: # 添加二级分组名称 if first_group_id: if not first_group_id.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) obi = ApiGroupLevelFirst.objects.filter(id=first_group_id, project=project_id) if obi: obi = ApiGroupLevelSecond( apiGroupLevelFirst=ApiGroupLevelFirst.objects.get( id=first_group_id), name=name) obi.save() else: return JsonResponse( code_msg=GlobalStatusCode.group_not_exist()) # 添加一级分组名称 else: obi = ApiGroupLevelFirst( project=Project.objects.get(id=project_id), name=name) obi.save() record_dynamic(project_id, '新增', '接口分组', '新增接口分组“%s”' % obi.name) return JsonResponse(data={'group_id': obi.pk}, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def update_host(request): """ 修改host project_id 项目id host_id 地址ID name 地址名称 host 地址域名 description 描述 :return: """ project_id = request.POST.get('project_id') host_id = request.POST.get('host_id') if not host_id.isdecimal() or not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get('name') host = request.POST.get('host') desc = request.POST.get('description') obj = Project.objects.filter(id=project_id) if obj: obi = GlobalHost.objects.filter(id=host_id, project=project_id) if obi: obm = GlobalHost.objects.filter(name=name).exclude(id=host_id) if len(obm) == 0: obi.update(project=Project.objects.get(id=project_id), name=name, host=host, description=desc) record = ProjectDynamic( project=Project.objects.get(id=project_id), type='修改', operationObject='HOST', user=User.objects.get(id=request.user.pk), description='修改HOST“%s”' % name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.host_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def test_time(request): """ 执行测试用例时间 case_id 用例ID :param request: :return: """ project_id = request.GET.get("project_id") obj = Project.objects.filter(id=project_id) if obj: try: data = AutomationTaskRunTimeSerializer( AutomationTaskRunTime.objects.filter( project=project_id).order_by("-startTime")[:10], many=True).data return JsonResponse(code_msg=GlobalStatusCode.success(), data=data) except: return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def update_name_group(request): """ 修改接口分组名称 project_id 项目ID name 名称 first_group_id 一级分组ID second_group_id 二级分组id :return: """ project_id = request.POST.get('project_id') name = request.POST.get('name') first_group_id = request.POST.get('first_group_id') second_group_id = request.POST.get('second_group_id') if not project_id.isdecimal() or not first_group_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = ApiGroupLevelFirst.objects.filter(id=first_group_id, project=project_id) if obi: # 修改二级分组名称 if second_group_id: if not second_group_id.isdecimal(): return JsonResponse( code_msg=GlobalStatusCode.parameter_wrong()) obm = ApiGroupLevelSecond.objects.filter( id=second_group_id, apiGroupLevelFirst=first_group_id) if obm: obm.update(name=name) else: return JsonResponse( code_msg=GlobalStatusCode.group_not_exist()) # 修改一级分组名称 else: obi.update(name=name) record_dynamic(project_id, '修改', '接口分组', '修改接口分组“%s”' % name) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.group_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def auto_lately_ten_time(request): """ 获取最近十次的测试数据 project_id 项目ID :param request: :return: """ project_id = request.GET.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obi = Project.objects.filter(id=project_id) if obi: try: data = AutomationTestLatelyTenTimeSerializer( AutomationTaskRunTime.objects.filter( project=project_id).order_by("-startTime")[:10], many=True).data for i in data: result = AutomationCaseTestResult.objects.filter( testTime=i["startTime"]) _pass = 0 fail = 0 error = 0 for j in result: if j.result == "PASS": _pass = _pass + 1 elif j.result == "ERROR": error = error + 1 elif j.result == "FAIL": fail = fail + 1 total = _pass + error + fail data[data.index(i)]["fail"] = "%.4f" % (fail / total) data[data.index(i)]["error"] = "%.4f" % (error / total) data[data.index(i)]["pass"] = "******" % (1 - fail / total - error / total) data.reverse() return JsonResponse(code_msg=GlobalStatusCode.success(), data=data) except: return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def disable_project(request): """ 禁用项目 project_id 项目ID :return: """ project_id = request.POST.get('project_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obj.update(status=False) record = ProjectDynamic(project=Project.objects.get(id=project_id), type='禁用', operationObject='项目', user=User.objects.get(id=request.user.pk), description='禁用项目“%s”' % obj[0].name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def post(self, request): """ 启用项目 :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result # 查找项目是否存在 obj = Project.objects.filter(id=data["project_id"]) if obj: obj.update(status=True) record_dynamic(project=data["project_id"], _type="启用", operationObject="域名", user=request.user.pk, data=obj[0].name) return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())