Fix sqlalchemy utils test cases for SA 0.9.x
To be able to run migration scripts on SQLite we've been providing a few workarounds for sqlalchemy-migrate and SQLAlchemy 0.7.x and 0.8.x branches in the form of sqlalchemy utils module. In 0.9.x releases a few workarounds become obsolete (due to improvements made to schema reflection for SQLite in SA), but our test cases still expect SA to raise exceptions in several cases. As long as our utils can work well with 0.9.x SA releases with our workarounds and without them, we can just skip the test cases expecting exceptions to be raised when SA version > 0.9.0 is used and continue to run them for older releases of SA. Closes-Bug: #1292284 Change-Id: Ic1453de16ec191f162d5604df76510d56429b32d
This commit is contained in:
parent
75ff5e5b7d
commit
087578b7a0
@ -42,6 +42,9 @@ from openstack.common import test
|
||||
from tests import utils as test_utils
|
||||
|
||||
|
||||
SA_VERSION = tuple(map(int, sqlalchemy.__version__.split('.')))
|
||||
|
||||
|
||||
class TestSanitizeDbUrl(test.BaseTestCase):
|
||||
|
||||
def test_url_with_cred(self):
|
||||
@ -350,9 +353,11 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
|
||||
Column('deleted', Boolean))
|
||||
table.create()
|
||||
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.change_deleted_column_type_to_id_type,
|
||||
engine, table_name)
|
||||
# reflection of custom types has been fixed upstream
|
||||
if SA_VERSION < (0, 9, 0):
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.change_deleted_column_type_to_id_type,
|
||||
engine, table_name)
|
||||
|
||||
fooColumn = Column('foo', CustomType())
|
||||
utils.change_deleted_column_type_to_id_type(engine, table_name,
|
||||
@ -360,8 +365,10 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
|
||||
|
||||
table = utils.get_table(engine, table_name)
|
||||
# NOTE(boris-42): There is no way to check has foo type CustomType.
|
||||
# but sqlalchemy will set it to NullType.
|
||||
self.assertTrue(isinstance(table.c.foo.type, NullType))
|
||||
# but sqlalchemy will set it to NullType. This has
|
||||
# been fixed upstream in recent SA versions
|
||||
if SA_VERSION < (0, 9, 0):
|
||||
self.assertTrue(isinstance(table.c.foo.type, NullType))
|
||||
self.assertTrue(isinstance(table.c.deleted.type, Integer))
|
||||
|
||||
def test_change_deleted_column_type_to_boolean(self):
|
||||
@ -416,9 +423,11 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
|
||||
Column('deleted', Integer))
|
||||
table.create()
|
||||
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.change_deleted_column_type_to_boolean,
|
||||
engine, table_name)
|
||||
# reflection of custom types has been fixed upstream
|
||||
if SA_VERSION < (0, 9, 0):
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.change_deleted_column_type_to_boolean,
|
||||
engine, table_name)
|
||||
|
||||
fooColumn = Column('foo', CustomType())
|
||||
utils.change_deleted_column_type_to_boolean(engine, table_name,
|
||||
@ -426,8 +435,10 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
|
||||
|
||||
table = utils.get_table(engine, table_name)
|
||||
# NOTE(boris-42): There is no way to check has foo type CustomType.
|
||||
# but sqlalchemy will set it to NullType.
|
||||
self.assertTrue(isinstance(table.c.foo.type, NullType))
|
||||
# but sqlalchemy will set it to NullType. This has
|
||||
# been fixed upstream in recent SA versions
|
||||
if SA_VERSION < (0, 9, 0):
|
||||
self.assertTrue(isinstance(table.c.foo.type, NullType))
|
||||
self.assertTrue(isinstance(table.c.deleted.type, Boolean))
|
||||
|
||||
def test_utils_drop_unique_constraint(self):
|
||||
@ -497,17 +508,21 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
|
||||
|
||||
engine.execute(test_table.insert(), values)
|
||||
warnings.simplefilter("ignore", SAWarning)
|
||||
# NOTE(boris-42): Missing info about column `foo` that has
|
||||
# unsupported type CustomType.
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.drop_unique_constraint,
|
||||
engine, table_name, uc_name, 'foo')
|
||||
|
||||
# NOTE(boris-42): Wrong type of foo instance. it should be
|
||||
# instance of sqlalchemy.Column.
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.drop_unique_constraint,
|
||||
engine, table_name, uc_name, 'foo', foo=Integer())
|
||||
# reflection of custom types has been fixed upstream
|
||||
if SA_VERSION < (0, 9, 0):
|
||||
# NOTE(boris-42): Missing info about column `foo` that has
|
||||
# unsupported type CustomType.
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.drop_unique_constraint,
|
||||
engine, table_name, uc_name, 'foo')
|
||||
|
||||
# NOTE(boris-42): Wrong type of foo instance. it should be
|
||||
# instance of sqlalchemy.Column.
|
||||
self.assertRaises(utils.ColumnError,
|
||||
utils.drop_unique_constraint,
|
||||
engine, table_name, uc_name, 'foo',
|
||||
foo=Integer())
|
||||
|
||||
foo = Column('foo', CustomType, default=0)
|
||||
utils.drop_unique_constraint(
|
||||
|
Loading…
Reference in New Issue
Block a user