summaryrefslogtreecommitdiff
path: root/tests/sqlalchemy/test_utils.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-09-24 15:04:53 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-09-24 15:04:53 -0400
commit7a3e091c1c9cc9ae6e34279c7c99c9989afd8894 (patch)
tree97ede8905e5379ada56f1ce40842066c5bb7ec31 /tests/sqlalchemy/test_utils.py
parent3fdafcd17f85e532342d5ddb45b972b5c462f843 (diff)
downloadoslo-db-7a3e091c1c9cc9ae6e34279c7c99c9989afd8894.tar.gz
Unwrap DialectFunctionDispatcher from itself.
The DialectFunctionDispatcher.dispatch_for() decorator method necessarily returns the dispatcher itself and not the decorated function, so that the object can continue to be re-used even if the function name is the same as that of the dispatcher. In order to support a single function being wrapped by the dispatcher multiple times with different criteria, dispatch_for() will now check for the last function wrapped and use that. Change-Id: I331670d9b76ae30e7a666648e7e2d4c72641c9ff Closes-Bug: #1373568
Diffstat (limited to 'tests/sqlalchemy/test_utils.py')
-rw-r--r--tests/sqlalchemy/test_utils.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/sqlalchemy/test_utils.py b/tests/sqlalchemy/test_utils.py
index a4cd3f2..742cd38 100644
--- a/tests/sqlalchemy/test_utils.py
+++ b/tests/sqlalchemy/test_utils.py
@@ -990,6 +990,41 @@ class TestDialectFunctionDispatcher(test_base.BaseTestCase):
callable_fn.mock_calls
)
+ def test_multiple_nesting(self):
+ callable_fn = mock.Mock(
+ default=mock.Mock(return_value=None),
+ mysql=mock.Mock(return_value=None)
+ )
+
+ dispatcher = utils.dispatch_for_dialect("*", multiple=True)(
+ callable_fn.default)
+
+ dispatcher = dispatcher.dispatch_for("mysql+mysqlconnector")(
+ dispatcher.dispatch_for("mysql+mysqldb")(
+ callable_fn.mysql
+ )
+ )
+
+ mysqldb_url = sqlalchemy.engine.url.make_url("mysql+mysqldb://")
+ mysqlconnector_url = sqlalchemy.engine.url.make_url(
+ "mysql+mysqlconnector://")
+ sqlite_url = sqlalchemy.engine.url.make_url("sqlite://")
+
+ dispatcher(mysqldb_url, 1)
+ dispatcher(mysqlconnector_url, 2)
+ dispatcher(sqlite_url, 3)
+
+ self.assertEqual(
+ [
+ mock.call.mysql(mysqldb_url, 1),
+ mock.call.default(mysqldb_url, 1),
+ mock.call.mysql(mysqlconnector_url, 2),
+ mock.call.default(mysqlconnector_url, 2),
+ mock.call.default(sqlite_url, 3)
+ ],
+ callable_fn.mock_calls
+ )
+
def test_single_retval(self):
dispatcher, callable_fn = self._single_fixture()
callable_fn.mysql_mysqldb.return_value = 5