예제 #1
0
    def copy_config(cls, project_id, configs):
        # 获取新config id 列表(不包含需要新增的配置)
        new_config_ids = [config[0] for config in configs if config[0]]
        # 获取原config id 列表
        config_ids = cls.query.filter_by(project_id=project_id).with_entities(
            cls.id).all()
        old_config_ids = [list(x)[0] for x in config_ids]
        # 需要删除的config id 列表
        delete_config_ids = list(
            set(old_config_ids).difference(set(new_config_ids)))
        # 需要新增的配置
        add_configs = [config for config in configs if config[0] is None]
        # 需要修改的配置(原配置 已经除去被删除 且不包括新增配置)
        update_configs = [config for config in configs if config[0]]

        try:
            # 删除config
            if delete_config_ids:
                for cid in delete_config_ids:
                    config = cls.query.filter_by(
                        id=cid, project_id=project_id).first_or_404()
                    db.session.delete(config)
                db.session.flush()

            # 新增config
            if add_configs:
                for c in add_configs:
                    case_id = c[1]
                    is_run = c[2]
                    order = c[3]
                    case = Case.query.filter_by(id=case_id).first_or_404()
                    config = cls(project_id, order, case_id, case.name, is_run,
                                 case.info, case.url, case.method, case.submit,
                                 case.header, case.data, case.deal,
                                 case.condition, case.expect, case.assertion,
                                 case.type)
                    db.session.add(config)
                db.session.flush()

            # 修改原用例(非新增) 是否执行 排序
            if update_configs:
                for c in update_configs:
                    config_id = c[0]
                    is_run = c[2]
                    order = c[3]
                    config = cls.query.filter_by(id=config_id).first_or_404()
                    config.is_run = is_run
                    config.order = order
                db.session.flush()

            db.session.commit()
        except Exception:
            db.session.rollback()
            raise UnknownException(msg='修改配置异常')
예제 #2
0
    def edit_project(cls, pid, form):
        pid = int(pid)
        project = cls.query.filter_by(id=pid, delete_time=None).first_or_404()
        project.is_running()
        project.user_id_auth()
        # name 组内唯一 此处判断不允许重复
        project_by_name = cls.query.filter_by(name=form.name.data,
                                              delete_time=None).first()
        # 获取目标分组当前的授权人员
        old_user_auth = UserAuth.query.filter_by(
            auth_id=pid, _type=UserAuthEnum.PROJECT.value).all()
        old_users = [user.user_id for user in old_user_auth]
        # 新的授权人员
        new_users = form.users.data
        if project_by_name == project or project_by_name is None:
            try:
                project.id = pid
                project.name = form.name.data
                project.server = form.server.data
                project.header = form.header.data
                project.info = form.info.data
                project.send_email = form.sendEmail.data
                project.email_strategy = EmailStrategyEnum(
                    form.emailStrategy.data)
                project.copy_person = form.copyPerson.data
                # 维护人
                project.user = form.user.data
                if form.users.data is not None:
                    # 旧人员列表中有 新人员列表中没有,这部分删除
                    old = list(set(old_users).difference(set(new_users)))
                    if old:
                        for user_id in old:
                            user = UserAuth.query.filter_by(
                                user_id=user_id,
                                _type=UserAuthEnum.PROJECT.value,
                                auth_id=pid).first_or_404()
                            db.session.delete(user)
                    # 新人员列表中有 旧人员列表中没有,这部分新增
                    new = list(set(new_users).difference(set(old_users)))
                    if new:
                        for user_id in new:
                            user_auth = UserAuth()
                            user_auth.user_id = user_id
                            user_auth.auth_id = pid
                            user_auth.type = UserAuthEnum.PROJECT
                            db.session.add(user_auth)
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                raise UnknownException(msg='新增异常请检查数据重试')
        elif project_by_name is not None:
            raise ParameterException(msg='工程已存在')

        return True
예제 #3
0
def collect():
    uid = request.args["id"]
    cid = request.args["cid"]

    if uid and cid:

        if User().collect(id=uid, cid=cid):
            return Success(msg="收藏成功")
        else:
            return UnknownException()
    else:
        return ParameterException()
예제 #4
0
 def updateConfig(self, url, method, submit, header, data, deal, condition,
                  expect, assertion):
     try:
         self.url = url
         self.method = CaseMethodEnum(method)
         self.submit = CaseSubmitEnum(submit)
         self.header = header
         self.data = data
         self.deal = CaseDealEnum(deal)
         self.condition = condition
         self.expect = expect
         self.assertion = CaseAssertEnum(assertion)
         db.session.commit()
     except Exception:
         db.session.rollback()
         raise UnknownException(msg='修改配置异常')
예제 #5
0
파일: wechat.py 프로젝트: TianJin85/starter
def activity():
    if request.method == "POST":
        form = Ctivity_Form(
            ImmutableMultiDict(eval(str(request.data, encoding='utf-8'))))
        if form.validate():
            result = eval(str(request.data, encoding='utf-8'))
            result.pop("num")
            if Ctivity.add_ctivity(**result):
                return Success(msg="发布活动成功")
            return UnknownException(msg="发布活动失败、活动名是否重复?")
    if request.method == "DELETE":
        return jsonify(request.data)

    if request.method == "PUT":
        return jsonify(request.data)

    return {"methods": ["POST", "DELETE", "PUT", "GET"]}
예제 #6
0
    def edit_group(cls, gid, form):
        gid = int(gid)
        group = cls.query.filter_by(id=gid, delete_time=None).first_or_404()
        group.user_id_auth()
        # name 组内唯一 此处判断不允许重复
        group_by_name = CaseGroup.query.filter_by(name=form.name.data,
                                                  delete_time=None).first()
        # 获取目标分组当前的授权人员
        old_user_auth = UserAuth.query.filter_by(
            auth_id=gid, _type=UserAuthEnum.GROUP.value).all()
        old_users = [user.user_id for user in old_user_auth]
        # 新的授权人员
        new_users = form.users.data
        if group_by_name == group or group_by_name is None:
            try:
                group.id = gid
                group.name = form.name.data
                group.info = form.info.data
                if form.users.data is not None:
                    # 旧人员列表中有 新人员列表中没有,这部分删除
                    old = list(set(old_users).difference(set(new_users)))
                    if old:
                        for user_id in old:
                            user = UserAuth.query.filter_by(
                                user_id=user_id,
                                _type=UserAuthEnum.GROUP.value,
                                auth_id=gid).first_or_404()
                            db.session.delete(user)
                    # 新人员列表中有 旧人员列表中没有,这部分新增
                    new = list(set(new_users).difference(set(old_users)))
                    if new:
                        for user_id in new:
                            user_auth = UserAuth()
                            user_auth.user_id = user_id
                            user_auth.auth_id = gid
                            user_auth.type = UserAuthEnum.GROUP
                            db.session.add(user_auth)
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                raise UnknownException(msg='新增异常请检查数据重试')
        elif group_by_name is not None:
            raise ParameterException(msg='分组已存在')

        return True
예제 #7
0
    def remove_project(cls, pid):
        project = cls.query.filter_by(id=pid, delete_time=None).first_or_404()
        project.is_running()
        project.user_id_auth()

        try:
            # 删除分组用户权限表,物理删除
            user_auth = UserAuth.query.filter_by(
                auth_id=pid, _type=UserAuthEnum.PROJECT.value).all()
            if user_auth:
                users = [user.user_id for user in user_auth]
                for user in users:
                    user = UserAuth.query.filter_by(
                        user_id=user,
                        _type=UserAuthEnum.PROJECT.value,
                        auth_id=pid).first()
                    db.session.delete(user)
            # 删除工程,逻辑删除
            project.delete_time = datetime.now()
            # 删除工程的用户自定义参数
            project.set_user_parameters()
            # 删除工程对应的定时任务
            from app.models.scheduler import Scheduler
            schedulers = Scheduler.query.filter_by(project_id=project.id,
                                                   delete_time=None).all()
            for scheduler in schedulers:
                scheduler.remove_job()
            # 删除副本工程配置表 物理删除
            copyConfigs = ConfigCopy.query.filter_by(project_id=pid).all()
            for config in copyConfigs:
                db.session.delete(config)
            # 删除关联工程配置表 物理删除
            relationConfigs = ConfigRelation.query.filter_by(
                project_id=pid).all()
            for config in relationConfigs:
                db.session.delete(config)
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            raise UnknownException(msg='删除异常请重试')
        return True
예제 #8
0
def enroll():
    userid = request.args["userid"]
    form = MessageForm(request.form)

    if request.method == "POST":
        print(request.form.to_dict())
        if form.validate():
            try:
                result = request.form.to_dict()
                uid = result["userid"]
                code = str(result["code"])

                if code == codes[uid]["code"]["code"]:
                    minute = (datetime.now() -
                              codes[uid]["code"]["date"]).seconds / 60
                    codes.pop(uid, "")  # 删除验证码
                    if minute > 5:

                        imgpath = Save(result=result).get_data()  # 保存图片获取地址
                        try:
                            cardidinfo = Message.set_cardid(result["cardid"])
                            enroll_data(result, imgpath, cardidinfo)
                            return Success(msg="报名成功")
                        except:
                            return UnknownException(msg="请检查身份证是否输入正确")
                    else:
                        Success(msg="验证码已过期")
                return Success(msg="验证码不正确")
            except os.error as e:
                return jsonify({"errors": e, "status": 500})
        else:
            error_data = ""
            for items in form.errors.values():
                for item in items:
                    error_data += item + "\n"

            return jsonify({"errors": error_data, "status": 300})

    return render_template("enroll.html", userid=userid)