()
添加用例集合
添加用例集合
添加用例集合
def add_set():
    """ 添加用例集合 """
    data = request.json
    project_id = data.get('projectId')
    name = data.get('name')
    if not project_id:
        return jsonify({'msg': '请先选择首页项目', 'status': 0})
    if not name:
        return jsonify({'msg': '用例集名称不能为空', 'status': 0})
    ids = data.get('id')
    num = auto_num(data.get('num'), CaseSet, project_id=project_id)
    if ids:
        old_data = CaseSet.query.filter_by(id=ids).first()
        if CaseSet.query.filter_by(name=name, project_id=project_id).first() and name != old_data.name:
            return jsonify({'msg': '用例集名字重复', 'status': 0})
        old_data.name = name
        old_data.project_id = project_id
        db.session.commit()
        return jsonify({'msg': '修改成功', 'status': 1})
    else:
        if CaseSet.query.filter_by(name=name, project_id=project_id).first():
            return jsonify({'msg': '用例集名字重复', 'status': 0})
        else:
            new_set = CaseSet(name=name, project_id=project_id, num=num)
            db.session.add(new_set)
            db.session.commit()
            return jsonify({'msg': '新建成功', 'status': 1})
def add_set ( ) : data = request . json project_id = data . get ( 'projectId' ) name = data . get ( 'name' ) if not project_id : return jsonify ( { 'msg' : '请先选择首页项目', 'status': 0}) if not name : return jsonify ( { 'msg' : '用例集名称不能为空', 'status': 0}) ids = data . get ( 'id' ) num = auto_num ( data . get ( 'num' ) , CaseSet , project_id = project_id ) if ids : old_data = CaseSet . query . filter_by ( id = ids ) . first ( ) if CaseSet . query . filter_by ( name = name , project_id = project_id ) . first ( ) and name != old_data . name : return jsonify ( { 'msg' : '用例集名字重复', 'status': 0} ) old_data . name = name old_data . project_id = project_id db . session . commit ( ) return jsonify ( { 'msg' : '修改成功', 'statu s : 1}) else : if CaseSet . query . filter_by ( name = name , project_id = project_id ) . first ( ) : return jsonify ( { 'msg' : '用例集名字重复', 'status': 0} ) else : new_set = CaseSet ( name = name , project_id = project_id , num = num ) db . session . add ( new_set ) db . session . commit ( ) return jsonify ( { 'msg' : '新建成功', 'statu s : 1})