예제 #1
0
    def post(self):
        user = g.user.username
        parse = reqparse.RequestParser(argument_class=MyArgument)
        parse.add_argument("caseName", type=str, required=True, help="caseName 不能为空")
        parse.add_argument("caseInterfaceId", type=str, required=True, help="caseInterfaceId 不能为空")
        parse.add_argument("caseProjectId", type=str, required=True, help="caseProjectId 不能为空")
        parse.add_argument("caseDesc", type=str, default="")
        caseName = parse.parse_args().get("caseName")
        caseDesc = parse.parse_args().get("caseDesc")
        caseInterfaceId = parse.parse_args().get("caseInterfaceId")
        caseProjectId = parse.parse_args().get("caseProjectId")

        # 判断是否重复
        Case.assertName(caseName)
        # 判断caseProjectId,caseInterfaceId
        Project.assertIdExisted(caseProjectId)
        Interfaces.assertIdExisted(caseInterfaceId)

        # 解析step
        caseSteps = request.json.get('caseSteps')
        if not caseSteps:
            return jsonify(dict(code=1, data="", err="caseSteps 不能为空"))

        caseSteps = self.__stepOpt(caseSteps=caseSteps)

        try:
            case = Case(name=caseName, desc=caseDesc, request=caseSteps, interface_id=caseInterfaceId,
                        project_id=caseProjectId,
                        author=user)
            case.save()
            return jsonify(dict(code=0, data=case.id, msg='ok'))
예제 #2
0
    def post(self):
        creator = g.user.username
        parse = reqparse.RequestParser(argument_class=MyArgument)
        parse.add_argument("projectId",
                           type=str,
                           required=True,
                           help="projectId 不能为空")
        parse.add_argument("caseName",
                           type=str,
                           required=True,
                           help="caseName 不能为空")
        parse.add_argument("caseDesc", type=str, default="")
        parse.add_argument("headless", type=str, default=False)
        parse.add_argument("windowsSize", type=str, default=None)

        headless = parse.parse_args().get("headless")
        windowsSize = parse.parse_args().get("windowsSize")

        projectId = parse.parse_args().get('projectId')
        Project.assertIdExisted(projectId)

        caseName = parse.parse_args().get('caseName')
        UICase.assertName(caseName)

        caseDesc = parse.parse_args().get('caseDesc')
        steps = self._del_step_info(request.json.get('caseSteps'))

        try:
            u = UICase(name=caseName,
                       desc=caseDesc,
                       creator=creator,
                       project_id=projectId,
                       headless=headless,
                       windowsSize=windowsSize)
            for step in steps:
                s = Steps(name=step['name'],
                          desc=step['desc'],
                          is_method=step['is_method'],
                          type=step['type'],
                          locator=step['locator'],
                          do=step['do'],
                          value=step['value'],
                          variable=step['variable'],
                          validate=step['validate'])
                u.casesteps.append(s)
            u.save()

            return jsonify(dict(code=1, data=u.id, msg='ok'))

        except Exception as e:
            log.exception(e)
            db.session.rollback()
            return jsonify(dict(code=0, err=f"错误:{str(e)}"))
        finally:
            db.session.close()
예제 #3
0
    def post(self):
        parse = reqparse.RequestParser(argument_class=MyArgument)
        parse.add_argument("projectName", type=str, required=True, help="projectName 不能为空")
        parse.add_argument("projectDesc", type=str)
        projectName = parse.parse_args().get('projectName')
        projectDesc = parse.parse_args().get('projectDesc')

        Project.assertName(projectName)

        try:
            Project(name=projectName, desc=projectDesc).save()
            return jsonify(dict(code=0, data="", msg="ok"))
        except Exception as e:
            log.exception(e)
            return jsonify(dict(code=0, err=f"{e}"))
예제 #4
0
    def post(self):
        projectId = request.json.get('projectId')
        if not projectId:
            return jsonify(dict(code=1, err="projectId不能为空"))

        try:
            if isinstance(projectId, (str, int)):
                Project.assertIdExisted(projectId).Delete()

                return jsonify(dict(code=0, data="", msg="ok"))
            elif isinstance(projectId, list):
                for i in projectId:
                    Project.assertIdExisted(i).Delete()
                return jsonify(dict(code=0, data="", msg="ok"))
        except Exception as e:
            log.exception(e)
            return jsonify(dict(code=0, err=f"{e}"))
예제 #5
0
 def delete(self):
     projectId = request.json.get('projectId')
     if not projectId:
         return jsonify(dict(code=1, err="projectId不能为空"))
     try:
         p = Project.get(projectId)
         p.delete()
         return jsonify(dict(code=0, data="", msg="ok"))
     except Exception as e:
         log.exception(e)
         return jsonify(dict(code=0, err=f"{e}"))
예제 #6
0
 def get(self):
     """
     获取project  id,[id,id].None 三种
     """
     try:
         pid = request.args.get("projectId")
         if pid:
             projects = [Project.get(pid)]
         else:
             projects = Project.all()
         data = {
             "code": 0,
             "msg": "ok",
             "data": [
                 {"id": i.id, "status": i.status, "project_name": i.project_name, "project_desc": i.project_desc} for
                 i
                 in projects]
         }
         return jsonify(data)
     except Exception as e:
         db.session.rollback()
         log.exception(str(e))
         return jsonify(dict(code=1, err=f"错误:{str(e)}"))
예제 #7
0
    def put(self):
        pName = request.json.get("projectName")
        pDesc = request.json.get("projectDesc")
        pId = request.json.get('projectId')

        if not pId:
            return jsonify(dict(code=1, err="传入必传"))

        try:
            p = Project.get(pId)
            p.project_name = pName
            p.project_desc = pDesc
            db.session.commit()
            return jsonify(dict(code=0, data=p.id, msg="ok"))

        except Exception as e:
            log.exception(e)
            return jsonify(dict(code=0, err=f"{e}"))