def test_check_shadow_table(self): table_name = 'test_check_shadow_table' table = Table(table_name, self.meta, Column('id', Integer, primary_key=True), Column('a', Integer), Column('c', String(256))) table.create() # check missing shadow table self.assertRaises(NoSuchTableError, utils.check_shadow_table, self.engine, table_name) shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, self.meta, Column('id', Integer), Column('a', Integer)) shadow_table.create() # check missing column self.assertRaises(exception.PatronException, utils.check_shadow_table, self.engine, table_name) # check when all is ok c = Column('c', String(256)) shadow_table.create_column(c) self.assertTrue(utils.check_shadow_table(self.engine, table_name)) # check extra column d = Column('d', Integer) shadow_table.create_column(d) self.assertRaises(exception.PatronException, utils.check_shadow_table, self.engine, table_name)
def _check_231(self, engine, data): self.assertColumnExists(engine, 'instances', 'ephemeral_key_uuid') instances = oslodbutils.get_table(engine, 'instances') self.assertIsInstance(instances.c.ephemeral_key_uuid.type, sqlalchemy.types.String) self.assertTrue(db_utils.check_shadow_table(engine, 'instances'))
def test_create_shadow_table_by_table_instance(self): table_name = 'test_create_shadow_table_by_table_instance' table = Table(table_name, self.meta, Column('id', Integer, primary_key=True), Column('a', Integer), Column('b', String(256))) table.create() utils.create_shadow_table(self.engine, table=table) self.assertTrue(utils.check_shadow_table(self.engine, table_name))
def test_check_shadow_table_with_unsupported_sqlite_type(self): table_name = 'test_check_shadow_table_with_unsupported_sqlite_type' table = Table(table_name, self.meta, Column('id', Integer, primary_key=True), Column('a', Integer), Column('c', CustomType)) table.create() shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, self.meta, Column('id', Integer, primary_key=True), Column('a', Integer), Column('c', CustomType)) shadow_table.create() self.assertTrue(utils.check_shadow_table(self.engine, table_name))
def test_create_shadow_table_not_supported_type(self): table_name = 'test_create_shadow_table_not_supported_type' table = Table(table_name, self.meta, Column('id', Integer, primary_key=True), Column('a', CustomType)) table.create() # reflection of custom types has been fixed upstream if SA_VERSION < (0, 9, 0): self.assertRaises(oslodbutils.ColumnError, utils.create_shadow_table, self.engine, table_name=table_name) utils.create_shadow_table(self.engine, table_name=table_name, a=Column('a', CustomType())) self.assertTrue(utils.check_shadow_table(self.engine, table_name))
def _post_downgrade_231(self, engine): self.assertColumnNotExists(engine, 'instances', 'ephemeral_key_uuid') self.assertTrue(db_utils.check_shadow_table(engine, 'instances'))