class CaseInterface(_Case): __tablename__ = 'case_interface' c_method = db.Column(db.String(10), nullable=False, comment='请求方式') c_url = db.Column(db.Text, nullable=False, comment='请求地址') c_headers = db.Column(db.Text, nullable=False, comment='请求头信息') c_body = db.Column(db.Text, nullable=False, comment='请求主体') case_assert = db.relationship('Case_Assert', backref=db.backref('case_interface'), lazy='dynamic', cascade='all, delete-orphan') case_result = db.relationship('Case_Result', backref=db.backref('case_interface'), lazy='dynamic', cascade='all, delete-orphan') case_out_param = db.relationship('Case_Output_Parameter', backref=db.backref('case_interface'), lazy='dynamic', cascade='all, delete-orphan') def __init__(self, name, creator, method, url, header, body, desc, uid): self.c_name = name self.p_creator = creator self.c_method = method self.c_url = url self.c_headers = repr(header) self.c_body = repr(body) self.c_desc = repr(desc) self.uid = uid def __repr__(self): return '<CASE ID:%r>' % self.c_id
class SuiteCase(db.Model): __tablename__ = 'suite_case_interface' scid = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True, comment='场景用例ID') scName = db.Column(db.String(128), nullable=False, comment='用例名称') scNo = db.Column(db.Integer, nullable=True, comment='用例在场景中的序顺号') create_time = db.Column(db.DateTime, default=datetime.datetime.now(), comment='创建时间') update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间') p_creator = db.Column(db.String(20), nullable=False, comment='创建者') uid = db.Column(db.Integer, nullable=False, comment='创建者ID') scDesc = db.Column(db.String(200), nullable=False, comment="用例描述") scMethod = db.Column(db.String(10), nullable=False, comment='请求方式') scUrl = db.Column(db.Text, nullable=False, comment='请求地址') scHeaders = db.Column(db.Text, nullable=False, comment='请求头信息') scBody = db.Column(db.Text, nullable=False, comment='请求主体') case_assert = db.relationship('Suite_Case_Assert', backref=db.backref('suite_case_interface'), lazy='dynamic', cascade='all, delete-orphan') case_result = db.relationship('Suite_Case_Result', backref=db.backref('suite_case_interface'), lazy='dynamic', cascade='all, delete-orphan') case_out_param = db.relationship( 'Suite_Case_Output_Parameter', backref=db.backref('suite_case_interface'), lazy='dynamic', cascade='all, delete-orphan') sid = db.Column(db.Integer, db.ForeignKey('p_test_suite.sid', ondelete='CASCADE'), comment='场景ID') def __init__(self, scName, scNo, p_creator, uid, scDesc, scMethod, scUrl, scHeaders, scBody, sid): self.scName = scName self.scNo = scNo self.p_creator = p_creator self.uid = uid self.scDesc = scDesc self.scMethod = scMethod self.scUrl = scUrl self.scHeaders = scHeaders self.scBody = scBody self.sid = sid
class TestSuite(db.Model): __tablename__ = 'p_test_suite' sid = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True, comment='测试集ID') s_name = db.Column(db.String(50), nullable=False, comment='模块名称或测试集名称') s_desc = db.Column(db.String(150), nullable=False, comment='测试集描述') create_time = db.Column(db.DateTime, default=datetime.datetime.now(), comment='创建时间') update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间') p_creator = db.Column(db.String(50), nullable=False, comment='创建者') p_id = db.Column(db.Integer, db.ForeignKey('project.p_id', ondelete='CASCADE'), comment='项目ID') suite_case = db.relationship('SuiteCase', backref=db.backref('p_test_suite'), lazy='dynamic', cascade='all, delete-orphan') def __init__(self, s_name, p_creator, p_id, s_desc=''): self.s_name = s_name self.p_creator = p_creator self.p_id = p_id self.s_desc = s_desc def __repr__(self): return '<Suite ID:%r>' % self.sid
class Project(db.Model): __tablename__ = "project" p_id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True, comment='项目ID') p_name = db.Column(db.String(50), nullable=False, comment='项目名称') create_time = db.Column(db.DateTime, default=datetime.datetime.now(), comment='创建时间') update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间') p_creator = db.Column(db.String(50), nullable=False, comment='创建者') p_status = db.Column(db.Integer, nullable=False, default=0, comment='项目状态') p_desc = db.Column(db.String(150), nullable=False, comment='项目描述') user_id = db.Column(db.Integer, db.ForeignKey('user.uid', ondelete='RESTRICT'), comment='用户ID') test_suite = db.relationship('TestSuite', backref=db.backref('project'), lazy='dynamic', cascade='all, delete-orphan') def __init__(self, p_name, p_creator, user_id, p_desc): self.p_name = p_name self.p_creator = p_creator self.user_id = user_id self.p_desc = p_desc def __repr__(self): return "<ProjectID:%r>" % self.p_id
class User(db.Model): """ 用户表 """ __tablename__ = 'user' uid = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(10), nullable=False) password = db.Column(db.String(128), nullable=False) projects = db.relationship('Project', backref=db.backref('users')) vars = db.relationship('Variable', backref=db.backref('users')) def __init__(self, username, password): self.username = username self.password = password def __repr__(self): return '<User %r>' % self.username
class Permission(db.Model): __tablename__='permission' p_id=db.Column(db.Integer,autoincrement=True, primary_key=True) p_name=db.Column(db.String(16), unique=True) p_er=db.Column(db.String(16), unique=True) #添加多对多的反向引用,必须使用secondary指定中间关联表 #用权限查询角色时用查询到的权限对象:“权限对象.roles.all()”得到其对应的所有角色 roles=db.relationship('Role', secondary=r_p, backref=db.backref('permission', lazy=True)) #db.backref('permission', 中的permission用来反向关联,用角色查询其对应的所有权限。用查询到的 '角色对象.permission.all()'得到。 ###relationship可以放到任意一个类中都行,与之相反。###
class Post(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True, autoincrement=True) created = db.Column(db.Date, nullable=False) title = db.Column(db.String(20), nullable=False) body = db.Column(db.String(100), nullable=False) author_id = db.Column(db.Integer, db.ForeignKey('user.uid'), nullable=False) users = db.relationship('User', backref=db.backref('posts')) def __init__(self, title, content, author_id): self.title = title self.content = content self.author_id = author_id def __repr__(self): return '<Category %r>' % self.title