diff options
author | Matt Riedemann <mriedem@us.ibm.com> | 2014-08-05 07:10:14 -0700 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2014-08-05 07:11:03 -0700 |
commit | 4dde38bbb82d039720a9d059f0556f2821a6a4e7 (patch) | |
tree | d0f20bba9f2d26088702a3eb779e64d427bb6c82 /tests | |
parent | 4c18fca18e3cd0708b12c9d00897373cb36c3ea9 (diff) | |
download | oslo-db-4dde38bbb82d039720a9d059f0556f2821a6a4e7.tar.gz |
Handle DB2 SmallInteger type for change_deleted_column_type_to_boolean
With the DB2 sqlalchemy driver (ibm_db_sa), boolean columns are stored
as SmallInteger rather than Boolean (or TINYINT for mysql). This change
updates the two tests that were changing the deleted column to boolean
and then checking the type based on the backing engine so they work for
ibm_db_sa.
Also changes the assertion from assertTrue to assertIsInstance since it
will provide a clearer failure message.
Closes-Bug: #1312423
Change-Id: I42975119ecacaac89e7225f57f9f6b52c455ab6a
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sqlalchemy/test_utils.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/tests/sqlalchemy/test_utils.py b/tests/sqlalchemy/test_utils.py index e1285f9..cdb132b 100644 --- a/tests/sqlalchemy/test_utils.py +++ b/tests/sqlalchemy/test_utils.py @@ -26,7 +26,7 @@ from six import moves from six.moves.urllib import parse import sqlalchemy from sqlalchemy.dialects import mysql -from sqlalchemy import Boolean, Index, Integer, DateTime, String +from sqlalchemy import Boolean, Index, Integer, DateTime, String, SmallInteger from sqlalchemy import MetaData, Table, Column, ForeignKey from sqlalchemy.engine import reflection from sqlalchemy.exc import SAWarning, ResourceClosedError @@ -373,6 +373,8 @@ class TestMigrationUtils(db_test_base.DbTestCase): self.assertTrue(isinstance(table.c.deleted.type, Integer)) def test_change_deleted_column_type_to_boolean(self): + expected_types = {'mysql': mysql.TINYINT, + 'ibm_db_sa': SmallInteger} table_name = 'abc' table = Table(table_name, self.meta, Column('id', Integer, primary_key=True), @@ -382,14 +384,12 @@ class TestMigrationUtils(db_test_base.DbTestCase): utils.change_deleted_column_type_to_boolean(self.engine, table_name) table = utils.get_table(self.engine, table_name) - if self.engine.name != "mysql": - expected_type = Boolean - else: - expected_type = mysql.TINYINT - - self.assertTrue(isinstance(table.c.deleted.type, expected_type)) + self.assertIsInstance(table.c.deleted.type, + expected_types.get(self.engine.name, Boolean)) def test_change_deleted_column_type_to_boolean_with_fc(self): + expected_types = {'mysql': mysql.TINYINT, + 'ibm_db_sa': SmallInteger} table_name_1 = 'abc' table_name_2 = 'bcd' @@ -408,12 +408,8 @@ class TestMigrationUtils(db_test_base.DbTestCase): utils.change_deleted_column_type_to_boolean(self.engine, table_name_2) table = utils.get_table(self.engine, table_name_2) - if self.engine.name != "mysql": - expected_type = Boolean - else: - expected_type = mysql.TINYINT - - self.assertTrue(isinstance(table.c.deleted.type, expected_type)) + self.assertIsInstance(table.c.deleted.type, + expected_types.get(self.engine.name, Boolean)) @db_test_base.backend_specific('sqlite') def test_change_deleted_column_type_to_boolean_type_custom(self): |