def test_abstract(self): id_col = get_grt_column('id', 'table_test', 'INT(16)', isNotNull=1, autoIncrement=1) table = get_grt_table( 'table_test', columns=[id_col], indices=[get_grt_index('i_test', columns=[id_col])], comment="abstract=True") self.assertEquals( 'class TableTest(object):\n' '\n' ' __table_args__ = (\n' ' {\'mysql_charset\': \'utf8\', \'sqlite_autoincrement\': True}\n' ' )\n' '\n' ' id = Column(INTEGER, nullable=False, autoincrement=True, primary_key=True) # pylint: disable=invalid-name\n' '\n' ' def __repr__(self):\n' ' return self.__str__()\n' '\n' ' def __str__(self):\n' ' return "<TableTest(%(id)s)>" % self.__dict__', str(TableObject(table)))
def test_basics(self): id_col = get_grt_column('id', 'table_test', 'INT(16)', isNotNull=1, autoIncrement=1) name_col = get_grt_column('name', 'table_test', 'VARCHAR(145)', isNotNull=1, comment="toprint=True") description_col = get_grt_column('description', 'table_test', 'BLOB') table = get_grt_table( 'table_test', columns=[id_col, name_col, description_col], indices=[get_grt_index('i_test', columns=[id_col])]) self.assertEquals( 'class TableTest(DECLARATIVE_BASE):\n' '\n' ' __tablename__ = \'table_test\'\n' ' __table_args__ = (\n' ' {\'mysql_charset\': \'utf8\', \'sqlite_autoincrement\': True}\n' ' )\n' '\n' ' id = Column(INTEGER, nullable=False, autoincrement=True, primary_key=True) # pylint: disable=invalid-name\n' ' name = Column(VARCHAR(145), nullable=False)\n' ' description = Column(BLOB)\n' '\n' ' def __repr__(self):\n' ' return self.__str__()\n' '\n' ' def __str__(self):\n' ' return "<TableTest(%(id)s, %(name)s)>" % self.__dict__', str(TableObject(table)))
def test_indices(self): id_col = get_grt_column('id', 'table_test', 'INT(16)', isNotNull=1, autoIncrement=1) name_col = get_grt_column('name', 'table_test', 'VARCHAR(145)', isNotNull=1, comment="toprint=True") description_col = get_grt_column('description', 'table_test', 'BLOB') unique_1 = get_grt_column('unique_1', 'table_test', 'INT(16)') unique_2 = get_grt_column('unique_2', 'table_test', 'INT(16)') index_1 = get_grt_column('index_1', 'table_test', 'INT(16)') index_2 = get_grt_column('index_2', 'table_test', 'INT(16)') table = get_grt_table('table_test', columns=[ id_col, name_col, description_col, unique_1, unique_2, index_1, index_2 ], indices=[ get_grt_index('i_primary', columns=[id_col]), get_grt_index('i_unique_single', 'UNIQUE', columns=[name_col]), get_grt_index('i_index_single', 'INDEX', columns=[description_col]), get_grt_index('i_unique_multi', 'UNIQUE', columns=[unique_1, unique_2]), get_grt_index('i_index_multi', 'INDEX', columns=[index_1, index_2]), ]) self.maxDiff = None self.assertEquals( 'class TableTest(DECLARATIVE_BASE):\n' '\n' ' __tablename__ = \'table_test\'\n' ' __table_args__ = (\n' ' {\'mysql_charset\': \'utf8\', \'sqlite_autoincrement\': True},\n' ' UniqueConstraint("unique_1", "unique_2", name="i_unique_multi"),\n' ' Index("index_1", "index_2", name="i_index_multi")\n' ' )\n' '\n' ' id = Column(INTEGER, nullable=False, autoincrement=True, primary_key=True) # pylint: disable=invalid-name\n' ' name = Column(VARCHAR(145), nullable=False, unique=True)\n' ' description = Column(BLOB, index=True)\n' ' unique_1 = Column(INTEGER)\n' ' unique_2 = Column(INTEGER)\n' ' index_1 = Column(INTEGER)\n' ' index_2 = Column(INTEGER)\n' '\n' ' def __repr__(self):\n' ' return self.__str__()\n' '\n' ' def __str__(self):\n' ' return "<TableTest(%(id)s, %(name)s)>" % self.__dict__', str(TableObject(table)))
def test_with_foreignkeys(self): id_col = get_grt_column('id', 'table_test', 'INT(16)', isNotNull=1, autoIncrement=1) id_other_ref = get_grt_column('id', 'table_test_other', 'INT(16)', isNotNull=1) id_other = get_grt_column('id_other', 'table_test', 'INT(16)', isNotNull=1) id_other2 = get_grt_column('id_other2', 'table_test', 'INT(16)', isNotNull=1, comment="relation=False") id_other3 = get_grt_column('id_other3', 'table_test', 'INT(16)', isNotNull=1, comment="backref=False") id_other4 = get_grt_column('id_other4', 'table_test', 'INT(16)', isNotNull=1, comment="remote_side='alias'") id_other5 = get_grt_column('id_other5', 'table_test', 'INT(16)', isNotNull=1, comment="backrefname=newbr") id_other6 = get_grt_column('id_other6', 'table_test', 'INT(16)', isNotNull=1, comment="uselist=False") table = get_grt_table( 'table_test', columns=[ id_col, id_other, id_other2, id_other3, id_other4, id_other5, id_other6 ], indices=[get_grt_index('i_test', columns=[id_col])], foreignKeys=[ get_grt_foreignKey('fk_id_other', columns=[id_other], referencedColumns=[id_other_ref]), get_grt_foreignKey('fk_id_other2', columns=[id_other2], referencedColumns=[id_other_ref]), get_grt_foreignKey('fk_id_other3', columns=[id_other3], referencedColumns=[id_other_ref]), get_grt_foreignKey('fk_id_other4', columns=[id_other4], referencedColumns=[id_other_ref]), get_grt_foreignKey('fk_id_other5', columns=[id_other5], referencedColumns=[id_other_ref]), get_grt_foreignKey('fk_id_other6', columns=[id_other6], referencedColumns=[id_other_ref]), ]) self.maxDiff = None self.assertEquals( 'class TableTest(DECLARATIVE_BASE):\n' '\n' ' __tablename__ = \'table_test\'\n' ' __table_args__ = (\n' ' {\'mysql_charset\': \'utf8\', \'sqlite_autoincrement\': True}\n' ' )\n' '\n' ' id = Column(INTEGER, nullable=False, autoincrement=True, primary_key=True) # pylint: disable=invalid-name\n' ' id_other = Column(\n' ' INTEGER, ForeignKey("table_test_other.id", name="fk_id_other", onupdate="SET NULL"), nullable=False\n' ' )\n' ' id_other2 = Column(\n' ' INTEGER, ForeignKey("table_test_other.id", name="fk_id_other2", onupdate="SET NULL"), nullable=False\n' ' )\n' ' id_other3 = Column(\n' ' INTEGER, ForeignKey("table_test_other.id", name="fk_id_other3", onupdate="SET NULL"), nullable=False\n' ' )\n' ' id_other4 = Column(\n' ' INTEGER, ForeignKey("table_test_other.id", name="fk_id_other4", onupdate="SET NULL"), nullable=False\n' ' )\n' ' id_other5 = Column(\n' ' INTEGER, ForeignKey("table_test_other.id", name="fk_id_other5", onupdate="SET NULL"), nullable=False\n' ' )\n' ' id_other6 = Column(\n' ' INTEGER, ForeignKey("table_test_other.id", name="fk_id_other6", onupdate="SET NULL"), nullable=False\n' ' )\n' '\n' ' tableTestOther = relationship("TableTestOther", foreign_keys=[id_other], backref="tableTest")\n' ' # relation for id_other2.ForeignKey ignored as configured in column comment\n' ' tableTestOther = relationship("TableTestOther", foreign_keys=[id_other3])\n' ' tableTestOther = relationship(\n' ' "TableTestOther", foreign_keys=[id_other4], backref="tableTest", remote_side=[\'alias\']\n' ' )\n' ' tableTestOther = relationship("TableTestOther", foreign_keys=[id_other5], backref="newbr")\n' ' tableTestOther = relationship("TableTestOther", foreign_keys=[id_other6], backref="tableTest", uselist=False)\n' '\n' ' def __repr__(self):\n' ' return self.__str__()\n' '\n' ' def __str__(self):\n' ' return "<TableTest(%(id)s)>" % self.__dict__', str(TableObject(table)))