Exemplo n.º 1
0
    def post(self, req):
        data = req.data

        if data["id"]:
            obj = models.CaseFile.objects.get(id=data["id"])
            serializersObj = serializers.S_AddInterface(data=data,
                                                        instance=obj,
                                                        many=False,
                                                        partial=True)
            if serializersObj.is_valid(raise_exception=True):
                validate_data = serializersObj.save()
                res_data = serializers.S_AddInterface(validate_data)
                res_obj = res_data.data
                return APIResponse(200,
                                   "更新成功",
                                   results=res_obj,
                                   status=status.HTTP_200_OK)
        else:
            serializersObj = serializers.S_AddInterface(data=data, many=False)
            if serializersObj.is_valid(raise_exception=True):
                validate_data = serializersObj.save()
                res_data = serializers.S_AddInterface(validate_data)
                res_obj = res_data.data
                return APIResponse(200,
                                   "添加成功",
                                   results=res_obj,
                                   status=status.HTTP_200_OK)
Exemplo n.º 2
0
    def post(self, req):
        data = req.data
        print(data)
        id = int(data["id"])
        if (models.ProjectList.objects.filter(id=id)):
            models.ProjectList.objects.filter(id=int(id)).delete()

            obj = models.ProjectList.objects.all()
            currentPage = int(data["page"])  # 当前请求的是第几页
            size = int(data["page_size"])  # 每页展示输了
            totalCount = len(obj)  # 总数
            PaginationObj = Pagination(totalCount,
                                       currentPage,
                                       perPageNum=size,
                                       allPageNum=11)
            all_page = PaginationObj.all_page()
            Many = ManyOrOne.IsMany(obj)
            valid_data = serializers.S_ProjectList(obj, many=Many)
            return APIResponse(200,
                               "删除成功",
                               results=valid_data.data,
                               total=totalCount,
                               page_size=all_page,
                               status=status.HTTP_200_OK)
        else:
            return APIResponse(400,
                               "项目不存在",
                               results=[],
                               status=status.HTTP_200_OK)
Exemplo n.º 3
0
 def post(self, req):
     id = req.data["id"]
     try:
         models.InterfaceFiles.objects.filter(id=id).delete()
         return APIResponse(200, "sucess", status=status.HTTP_200_OK)
     except:
         return APIResponse(409, "修改失败,请联系管理员", status=status.HTTP_200_OK)
Exemplo n.º 4
0
def custom_exception_handler(exc, context):

    response = exception_handler(exc, context)
    message = ""

    #这里可以风阻航一个方法--自定义报错返回
    if errorsMsg["Message"]:
        msg = errorsMsg["Message"]
        errorsMsg["Message"] = None
        return APIResponse(400,
                           msg,
                           status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                           exception=True)
    # 这个循环是取第一个错误的提示用于渲染
    print(exc.args)
    if response is None:
        return APIResponse(400,
                           "参数错误",
                           status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                           exception=True)
    else:
        for index, value in enumerate(response.data):
            if index == 0:
                key = value
                value = response.data[key]

                if isinstance(value, str):
                    message = value
                    if message == "Authentication credentials were not provided." or message == "Invalid Authorization header. No credentials provided.":
                        message = "用户未登录或登录态失效"
                else:
                    message = value[0]
        # print('123 = %s - %s - %s' % (context['view'], context['request'].method, exc))
        return APIResponse(409, message, status=status.HTTP_200_OK)
Exemplo n.º 5
0
 def post(self, req):
     cron = req.data["cron"]
     res = self.CronValid(cron)
     if int(res["status"]) == 1:
         return APIResponse(200, "", results=res, status=status.HTTP_200_OK)
     else:
         res["info"] = "Cron表达式格式错误"
         return APIResponse(200, "", results=res, status=status.HTTP_200_OK)
Exemplo n.º 6
0
    def post(self, req):
        id = req.data["id"]
        a = models.Environments.objects.all()
        obj = models.Environments.objects.filter(id=id).select_related()
        if obj:
            models.Environments.objects.filter(id=id).delete()
            return APIResponse(200, "删除成功", status=status.HTTP_200_OK)

        return APIResponse(200, "删除失败,环境不存在", status=status.HTTP_200_OK)
Exemplo n.º 7
0
    def get(self, req):
        params = req.query_params

        print(params)
        print(params.get("id"))
        print(params.keys())
        if "id" in params:
            #查询当前用户是否为该项目的创建人--如果是创建人则返回1-可以允许同步 否则不允许同步
            id = params.get("id")
            userId = params.get("userId")
            obj = models.ProjectList.objects.filter(
                Q(id=id) & Q(user_id=userId) & Q(status=0))
            if obj:
                res_data = serializers.S_ProjectList(obj[0], many=False)
                obj = res_data.data
                return APIResponse(200,
                                   "",
                                   results=obj,
                                   code=1,
                                   status=status.HTTP_200_OK)
            else:
                return APIResponse(200, "", code=0, status=status.HTTP_200_OK)
        else:
            try:
                obj = models.ProjectList.objects.all().order_by(
                    "create_time").reverse()  #根据创建时间从大到小排序
                currentPage = int(params["page"])  #当前请求的是第几页
                size = int(params["page_size"])  #每页展示输了
                totalCount = len(obj)  #总数
                PaginationObj = Pagination(totalCount,
                                           currentPage,
                                           perPageNum=size,
                                           allPageNum=11)
                all_page = PaginationObj.all_page()
                Many = ManyOrOne.IsMany(obj)
                valid_data = serializers.S_ProjectList(obj, many=Many)
                res_data = valid_data.data[PaginationObj.start():PaginationObj.
                                           end()]
                return APIResponse(200,
                                   "success",
                                   results=res_data,
                                   total=totalCount,
                                   page_size=all_page,
                                   status=status.HTTP_200_OK)

            except:
                obj = models.ProjectList.objects.all().order_by(
                    "create_time").reverse()  # 根据创建时间从大到小排序
                Many = ManyOrOne.IsMany(obj)
                valid_data = serializers.S_ProjectList(obj, many=Many)
                return APIResponse(200,
                                   "success",
                                   results=valid_data.data,
                                   status=status.HTTP_200_OK)
Exemplo n.º 8
0
 def post(self, req):
     data = req.data
     if int(data["Stype"]) == 1:  #校验sql
         res = self.sql(data)
         return APIResponse(200,
                            "SQL执行成功",
                            results=res,
                            status=status.HTTP_200_OK)
     else:
         res = self.box(data)
         return APIResponse(200,
                            "数据库连接成功",
                            results=res,
                            status=status.HTTP_200_OK)
Exemplo n.º 9
0
    def get(self, req):
        id = req.query_params["projectId"]
        total = None
        all_page = None
        page = None
        pageSize = None
        if "page" in req.query_params:
            page = req.query_params["page"]
            pageSize = req.query_params["pageSize"]

        obj = models.CasePlan.objects.select_related(
            "projectId",
            "userId").filter(projectId=id).order_by("createTime").reverse()
        serializersObj = serializers.S_AddCasePlan(obj, many=True)
        res_data = serializersObj.data
        if page:  #如果传了分页 则返回分页数据--否则返回所有数据
            total = len(res_data)  #数据总数
            PaginationObj = Pagination(total,
                                       page,
                                       perPageNum=pageSize,
                                       allPageNum=11)
            all_page = PaginationObj.all_page()
            res_data = res_data[PaginationObj.start():PaginationObj.end()]

        return APIResponse(200,
                           "success",
                           results=res_data,
                           total=total,
                           allPage=all_page,
                           status=status.HTTP_200_OK)
Exemplo n.º 10
0
    def post(self, req):

        data = req.data
        serializersObj = serializers.S_AddCasePlan(data=data, many=False)
        if serializersObj.is_valid(raise_exception=True):
            serializersObj.save()
            # res_data_obj=serializers.S_AddCasePlan(res_obj,many=False)
            # res_data=res_data_obj.data
            S = DeleteCasePlan()
            res = S.listPlan(req)
            data = json.loads(json.dumps(res["res_data"]))[0]
            # print(data)
            if int(data["runType"]
                   ["id"]) == 1:  #只要是选择定时都会去新建一个---只是该定时任务目前是暂停的
                arg = {
                    "id": data["id"],
                    "runType": data["runType"]["id"],
                    "userId": data["userId"]["id"],
                    "CaseCount": data["CaseCount"],
                    "projectId": data["projectId"]["id"],
                    "againScript": data["againScript"],
                    "cron": data["cron"],
                    "name": data["cname"],
                    "timedId": data["timedId"],
                    "taskId": data["taskId"]
                }
                # print(arg)
                TimedTask().task(arg)
            #新建如果是定时任务--那么就在任务列表插入一条数据---同时创建定时任务到beat表
            return APIResponse(200,
                               "计划创建成功",
                               results=res["res_data"],
                               total=res["total"],
                               allPage=res["all_page"],
                               status=status.HTTP_200_OK)
Exemplo n.º 11
0
 def post(self, req):
     l = {
         "results": [],
         "logList": [],
     }
     self.logRedis = conn("log")
     data = req.data
     res_data = req.data.dict()
     validateObj = serializers.S_debugCase(data=data, many=False)
     environmentsObj = self.Environmented(validateObj, res_data)
     res_data["environmentId"] = environmentsObj
     start = StartMethod(data["userId"])
     start()
     self.logger = logs(self.__class__.__module__)
     self.logger.info("单位开始执行")
     # s = InRequests(res_data["postMethod"], res_data["dataType"], environmentsObj,res_data["name"],self.logger)
     # response = s.run(res_data["attr"], res_data["headers"], res_data["data"])
     caseAction = CaseAction()
     response = caseAction.action(res_data, self.logger)
     l["results"].append(response)
     self.logger.info("单位执行结束")
     redisListLog = self.logRedis.lrange(
         "log:%s_%s" % (data["userId"], None), 0, -1)
     for log in redisListLog:
         l["logList"].append(log.decode("utf8"))
     #根据errors判断执行是否成功  断言另外处理
     self.logRedis.delete("log:%s_%s" % (data["userId"], None))
     #response--存入CaseResult  type=1
     userId = UserProfile.objects.get(id=data["userId"])
     models.CaseResult.objects.create(result=l,
                                      type=1,
                                      c_id=data["id"],
                                      userId=userId)
     return APIResponse(200, "sucess", results=l, status=status.HTTP_200_OK)
Exemplo n.º 12
0
 def get(self, request):
     data = models.Department.objects.all()
     data = serializers.S_Department(data, many=True)
     return APIResponse(200,
                        "success",
                        results=data.data,
                        status=status.HTTP_200_OK)
Exemplo n.º 13
0
 def post(self, req):
     serializersObj = serializers.S_addTimedTask(data=req.data, many=False)
     if serializersObj.is_valid(raise_exception=True):
         res_data = serializersObj.save()
         res_data = serializers.S_addTimedTask(res_data)
         data_obj = res_data.data
         res = self.taskList(req.data)
         s = myTimedTask()
         data = models.CasePlan.objects.get(id=data_obj["casePlanId"])
         arg = {
             "id": data.id,  #计划的id
             "t_id": data_obj["id"],
             "runType": 1,  #新增的定时任务始终执行类型始终都是为1
             "userId": data.userId.id,
             "CaseCount": data.CaseCount,
             "projectId": data.projectId.id,
             "againScript": data.againScript,
             "cron": data.cron,
             "taskName": data_obj["taskName"],
             "timedId": data_obj["status"]["id"]
             # "timedId": data["timedId"],
             # "taskId": data["taskId"]
         }
         s.run(arg)
         return APIResponse(200,
                            "计划创建成功",
                            results=res["res_data"],
                            total=res["total"],
                            allPage=res["all_page"],
                            status=status.HTTP_200_OK)
Exemplo n.º 14
0
    def post(self, req):
        data = req.data
        print(data.dict())
        id = req.data["id"]
        # print(data["postMethodsId"])
        # print(models.PostMethods.objects.get(id=data["postMethodsId"]))
        # data["postMethodsId"]=models.PostMethods.objects.get(id=data["postMethodsId"])
        oldObj = models.InterfaceFiles.objects.get(id=id)
        valida_obj = serializers.S_updateFiles(data=data,
                                               instance=oldObj,
                                               partial=True,
                                               many=False)
        if valida_obj.is_valid(raise_exception=True):
            res_obj = valida_obj.save()
            res_obj = serializers.S_updateFiles(res_obj)
            res_data = res_obj.data
            if res_data["post_header"]:
                res_data["post_header"] = json.loads(res_data["post_header"])
            if res_data["post_data"]:
                res_data["post_data"] = json.loads(res_data["post_data"])
            if res_data["res_header"]:
                res_data["res_header"] = json.loads(res_data["res_header"])
            if res_data["res_data"]:
                res_data["res_data"] = json.loads(res_data["res_data"])

            return APIResponse(200,
                               "sucess",
                               results=res_data,
                               status=status.HTTP_200_OK)
Exemplo n.º 15
0
 def get(self, req):
     data = req.query_params
     projectId = data["projectId"]
     obj = models.SqlBox.objects.filter(projectId_id=int(projectId))
     serializersObj = serializers.S_addSqlBox(obj, many=True)
     sqlBoxList = serializersObj.data
     sqlType = [
         {
             "id": 1,
             "name": "查"
         },
         {
             "id": 2,
             "name": "改"
         },
         {
             "id": 3,
             "name": "增"
         },
         {
             "id": 4,
             "name": "删"
         },
     ]
     return APIResponse(200,
                        "",
                        results={
                            "sqlBoxList": sqlBoxList,
                            "sqlType": sqlType
                        },
                        status=status.HTTP_200_OK)
Exemplo n.º 16
0
 def get(self, request, format=None):
     menus = models.Menu.objects.filter(parent=None)
     serializer = serializers.MenuSerializer(menus, many=True)
     return APIResponse(200,
                        "sucess",
                        results=serializer.data,
                        status=status.HTTP_200_OK)
Exemplo n.º 17
0
 def post(self, req):
     """删除
     参数同上
     """
     data = req.data
     id = data["id"]
     try:
         models.CaseResult.objects.get(id=id).delete()
     except:
         return APIResponse(409, "删除异常", status=status.HTTP_200_OK)
     res_data, all_page, total = self.page_c(data)
     return APIResponse(200,
                        "删除成功",
                        results=res_data,
                        total=total,
                        allPage=all_page,
                        status=status.HTTP_200_OK)
Exemplo n.º 18
0
 def get(self, req):
     data = req.query_params
     res_data, all_page, total = self.page_c(data)
     return APIResponse(200,
                        "sucess",
                        results=res_data,
                        total=total,
                        allPage=all_page,
                        status=status.HTTP_200_OK)
Exemplo n.º 19
0
    def get(self, req):
        data = req.query_params
        obj = models.InterfaceFiles.objects.filter(project=int(
            data["projectId"]),
                                                   id=int(data["id"]))
        obj = serializers.S_interfaceDetail(obj, many=True)
        obj = obj.data

        return APIResponse(200, "sucess", obj, status=status.HTTP_200_OK)
Exemplo n.º 20
0
 def post(self, req):
     serializersObj = serializers.S_AddCase(data=req.data)
     if serializersObj.is_valid(raise_exception=True):
         validate_data = serializersObj.save()
         res_data = serializers.S_AddCase(validate_data)
         res_data = res_data.data
         return APIResponse(200,
                            "添加成功",
                            results=res_data,
                            status=status.HTTP_200_OK)
Exemplo n.º 21
0
    def post(self, request):
        data = request.data
        print(data)

        validate_data = serializers.S_Register(data=data, many=False)
        if validate_data.is_valid(raise_exception=True):
            a = validate_data.save()
            print("data", validate_data)
            res_data = serializers.S_Register(a, many=False)
            print(res_data)
            return APIResponse(200,
                               "注册成功",
                               results=res_data.data,
                               status=status.HTTP_200_OK)
        else:
            return APIResponse(200,
                               "注册失败",
                               results={},
                               status=status.HTTP_200_OK)
Exemplo n.º 22
0
 def post(self, req):
     data = req.data
     valid_data = serializers.S_InterfaceFilesName(data=data, many=False)
     if valid_data.is_valid(raise_exception=True):
         res_data = valid_data.save()
         res_data = serializers.S_InterfaceFilesName(res_data)
         return APIResponse(200,
                            "添加成功",
                            data=res_data.data,
                            status=status.HTTP_200_OK)
Exemplo n.º 23
0
    def get(self, req):
        data = req.query_params

        res = addTimedTask().taskList(data, kwarg=self.isValid(data))
        return APIResponse(200,
                           "",
                           results=res["res_data"],
                           total=res["total"],
                           allPage=res["all_page"],
                           status=status.HTTP_200_OK)
Exemplo n.º 24
0
 def get(self, req):
     data = req.query_params
     s = PageMethod(models.SqlStatement, serializers.S_addSql, data)
     res = s.taskList(s.isValid())
     return APIResponse(200,
                        "",
                        results=res["res_data"],
                        total=res["total"],
                        allPage=res["all_page"],
                        status=status.HTTP_200_OK)
Exemplo n.º 25
0
 def get(self, req):
     data = req.query_params
     id = data["id"]
     obj = models.CaseResult.objects.get(id=id)
     serializersObj = serializers.S_CaseResults(obj)
     res_data = serializersObj.data["result"]
     return APIResponse(200,
                        "sucess",
                        results=eval(res_data),
                        status=status.HTTP_200_OK)
Exemplo n.º 26
0
 def post(self, req):
     id = req.data["id"]
     # projectId=req.data["projectId"]
     userId = req.data["userId"]
     fileId = req.data["fileId"]
     oldObj = models.InterfaceFiles.objects.filter(id=int(id))
     # Many=ManyOrOne.IsMany(oldObj)
     data = serializers.S_CopyFiles(oldObj, many=True)
     a = data.data
     try:
         b = json.loads(json.dumps(a))[0]
         b["resTypeId"] = b["res_type"]
         b["postMethodsId"] = b["post_methods"]
         b["postTypeId"] = b["post_type"]
         b["fileId"] = fileId
         b["projectId"] = b["project"]
         b["createUserId"] = userId
         del b["res_type"]
         del b["post_methods"]
         del b["post_type"]
         del b["file"]
         del b["id"]
         del b["update_time"]
         del b["create_time"]
         del b["project"]
         obj = serializers.S_AddFiles(data=b, many=False)
         if obj.is_valid(raise_exception=True):
             save_data = obj.save()
             res_data = serializers.S_AddFiles(save_data).data
             # 将数据库取出来的序列化列表数据读出来
             res_data["post_header"] = json.loads(res_data["post_header"])
             res_data["post_data"] = json.loads(res_data["post_data"])
             res_data["res_header"] = json.loads(res_data["res_header"])
             res_data["res_data"] = json.loads(res_data["res_data"])
             return APIResponse(200,
                                "sussces",
                                results=res_data,
                                status=status.HTTP_200_OK)
     except:
         return APIResponse(200,
                            "SUCESS",
                            results=a,
                            status=status.HTTP_200_OK)
Exemplo n.º 27
0
    def get(self, req):
        data = req.query_params

        s = SqlBoxMethods()
        res = s.taskList(data, kwarg=s.isValid(data))
        return APIResponse(200,
                           "",
                           results=res["res_data"],
                           total=res["total"],
                           allPage=res["all_page"],
                           status=status.HTTP_200_OK)
Exemplo n.º 28
0
 def get(self, req):
     projectId = req.query_params["projectId"]
     obj = models.InterfaceFilesName.objects.filter(project_id=projectId)
     print(obj, "1111")
     res_data = serializers.S_select_InterfaceFilesName(obj, many=True)
     res_data = res_data.data
     print(res_data)
     return APIResponse(200,
                        "sucess",
                        results=res_data,
                        status=status.HTTP_200_OK)
Exemplo n.º 29
0
 def get(self, req):
     params = req.query_params
     id = params.get("id")
     obj = models.CaseGroupFiles.objects.select_related(
         "projectId", "userId").filter(projectId_id=id)
     serializersObj = serializers.S_CaseGroupFiles(obj, many=True)
     # print(serializersObj.data)
     return APIResponse(200,
                        "sucess",
                        results=serializersObj.data,
                        status=status.HTTP_200_OK)
Exemplo n.º 30
0
 def post(self, req):
     data = req.data
     id = data["id"]
     models.SqlBox.objects.filter(id=id).delete()
     s = SqlBoxMethods()
     res = s.taskList(data, kwarg=s.isValid(data))
     return APIResponse(200,
                        "删除成功",
                        results=res["res_data"],
                        total=res["total"],
                        allPage=res["all_page"],
                        status=status.HTTP_200_OK)