summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavanum Srinivas <davanum@gmail.com>2016-01-14 21:08:44 -0500
committerTony Breeds <tony@bakeyournoodle.com>2016-03-11 12:00:02 +1100
commitae22f7f06083568e8c9c5fa885252cb46b5b9f02 (patch)
tree3668edabcf2291f1d8ff767822e62ec7bde37a75
parentc5f468d8fb237842aad54e5fdebd35a8be19df51 (diff)
downloadoslo-db-ae22f7f06083568e8c9c5fa885252cb46b5b9f02.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. NOTE(tonyb): We need to make the same change in .../old_import_api/.../test_exc_filters.py in the stable/kilo branch. This was removed in the liberty timeframe in If3036e03a68c2e865b5f0495c74fe8303de93d21 Closes-Bug: #1533861 Change-Id: Iab9f0e4b4dd337363dd7e705c1155f3f6517b404 (cherry picked from commit 543d577613a5ccc12f4482d9e2f9ce1f29db21b4) (cherry picked from commit 40004ebbca6c345da09cec4e91f85fc73ab18e70)
-rw-r--r--oslo_db/tests/old_import_api/sqlalchemy/test_exc_filters.py11
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py11
2 files changed, 16 insertions, 6 deletions
diff --git a/oslo_db/tests/old_import_api/sqlalchemy/test_exc_filters.py b/oslo_db/tests/old_import_api/sqlalchemy/test_exc_filters.py
index 4d4609a..253ea89 100644
--- a/oslo_db/tests/old_import_api/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/old_import_api/sqlalchemy/test_exc_filters.py
@@ -48,9 +48,14 @@ class _SQLAExceptionMatcher(object):
self.assertEqual(exc.__class__.__name__, exception_type)
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):
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index aafdcfb..11d03d8 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -48,9 +48,14 @@ class _SQLAExceptionMatcher(object):
self.assertEqual(exc.__class__.__name__, exception_type)
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):