diff options
author | Florian Haas <florian@hastexo.com> | 2014-01-24 23:05:31 +0100 |
---|---|---|
committer | Florian Haas <florian@hastexo.com> | 2014-01-24 23:05:31 +0100 |
commit | 7f689b54c8d47400f57e75ccf48be0fdca63f226 (patch) | |
tree | cbd4bbb59390c4727d5cc762c819a19ee8b39a0d /tests | |
parent | 4e7e1567b40128b71ff2ff20740d19a5484072f6 (diff) | |
download | oslo-db-7f689b54c8d47400f57e75ccf48be0fdca63f226.tar.gz |
Drop special case for MySQL traditional mode, update unit tests
Since there are no users of the special-case TRADITIONAL mode set,
it's OK to drop those references and use only the more flexible
one tuned via a config option.
Update the TRADITIONAL mode unit test, and also add one for
STRICT_ALL_TABLES mode.
Change-Id: Ie9df3aaa5f48d992b61a9ea480d1e17519f16422
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/db/sqlalchemy/test_sqlalchemy.py | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/tests/unit/db/sqlalchemy/test_sqlalchemy.py b/tests/unit/db/sqlalchemy/test_sqlalchemy.py index 323da4e..be04a41 100644 --- a/tests/unit/db/sqlalchemy/test_sqlalchemy.py +++ b/tests/unit/db/sqlalchemy/test_sqlalchemy.py @@ -255,13 +255,19 @@ class TestDBDisconnected(test.BaseTestCase): self._test_ping_listener_disconnected(connection) -class MySQLTraditionalModeTestCase(test_base.MySQLOpportunisticTestCase): +class MySQLModeTestCase(test_base.MySQLOpportunisticTestCase): + + def __init__(self, *args, **kwargs): + super(MySQLModeTestCase, self).__init__(*args, **kwargs) + # By default, run in empty SQL mode. + # Subclasses override this with specific modes. + self.mysql_mode = '' def setUp(self): - super(MySQLTraditionalModeTestCase, self).setUp() + super(MySQLModeTestCase, self).setUp() self.engine = session.create_engine(self.engine.url, - mysql_traditional_mode=True) + mysql_sql_mode=self.mysql_mode) self.connection = self.engine.connect() meta = MetaData() @@ -274,10 +280,45 @@ class MySQLTraditionalModeTestCase(test_base.MySQLOpportunisticTestCase): self.addCleanup(self.test_table.drop) self.addCleanup(self.connection.close) - def test_string_too_long(self): + def _test_string_too_long(self, value): with self.connection.begin(): - self.assertRaises(DataError, self.connection.execute, - self.test_table.insert(), bar='a' * 512) + self.connection.execute(self.test_table.insert(), + bar=value) + result = self.connection.execute(self.test_table.select()) + return result.fetchone()['bar'] + + def test_string_too_long(self): + value = 'a' * 512 + # String is too long. + # With no SQL mode set, this gets truncated. + self.assertNotEqual(value, + self._test_string_too_long(value)) + + +class MySQLStrictAllTablesModeTestCase(MySQLModeTestCase): + "Test data integrity enforcement in MySQL STRICT_ALL_TABLES mode." + + def __init__(self, *args, **kwargs): + super(MySQLStrictAllTablesModeTestCase, self).__init__(*args, **kwargs) + self.mysql_mode = 'STRICT_ALL_TABLES' + + def test_string_too_long(self): + value = 'a' * 512 + # String is too long. + # With STRICT_ALL_TABLES or TRADITIONAL mode set, this is an error. + self.assertRaises(DataError, + self._test_string_too_long, value) + + +class MySQLTraditionalModeTestCase(MySQLStrictAllTablesModeTestCase): + """Test data integrity enforcement in MySQL TRADITIONAL mode. + Since TRADITIONAL includes STRICT_ALL_TABLES, this inherits all + STRICT_ALL_TABLES mode tests. + """ + + def __init__(self, *args, **kwargs): + super(MySQLTraditionalModeTestCase, self).__init__(*args, **kwargs) + self.mysql_mode = 'TRADITIONAL' class EngineFacadeTestCase(test.BaseTestCase): |