diff options
author | Davanum Srinivas <davanum@gmail.com> | 2016-01-14 21:08:44 -0500 |
---|---|---|
committer | Davanum Srinivas <davanum@gmail.com> | 2016-01-15 06:42:48 -0500 |
commit | 543d577613a5ccc12f4482d9e2f9ce1f29db21b4 (patch) | |
tree | 2edfa9cde2e470f2b4839e4bb25a2521f6305990 | |
parent | cfa53ac438006a04217349b6e37195005e286d8e (diff) | |
download | oslo-db-543d577613a5ccc12f4482d9e2f9ce1f29db21b4.tar.gz |
Fix tests to work under both pymsysql 0.6.2 and 0.7.x
In 0.6.2, the exc.statement and exc.params were as follows:
exc.statement = {unicode} u'INSERT INTO resource_entity (id, foo_id)
VALUES (%s, %s)'
exc.params = {tuple} (1, 2)
In 0.7.1, the exc.statement and exc.params are as follows:
exc.statement = {unicode} u'INSERT INTO resource_entity (id, foo_id)
VALUES (%(id)s, %(foo_id)s)'
exc.params = {dict} {'id': 1, 'foo_id': 2}
So the easiest thing to support both is to use string interpolation
and then check if they are equal. This approach works for both py34
and py27 as well. Note that we still have to test the old way for
sqlite which has (?, ?) in the SQL statement.
Closes-Bug: #1533861
Change-Id: Iab9f0e4b4dd337363dd7e705c1155f3f6517b404
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_exc_filters.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py index dc1cd20..0d75c83 100644 --- a/oslo_db/tests/sqlalchemy/test_exc_filters.py +++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py @@ -57,9 +57,14 @@ class _SQLAExceptionMatcher(object): else: self.assertEqual(str(exc.orig).lower(), message.lower()) if sql is not None: - self.assertEqual(exc.statement, sql) - if params is not None: - self.assertEqual(exc.params, params) + if params is not None: + if '?' in exc.statement: + self.assertEqual(exc.statement, sql) + self.assertEqual(exc.params, params) + else: + self.assertEqual(exc.statement % exc.params, sql % params) + else: + self.assertEqual(exc.statement, sql) class TestsExceptionFilter(_SQLAExceptionMatcher, oslo_test_base.BaseTestCase): |