diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py index e1ea6ac..3afb016 100644 --- a/oslo_db/tests/sqlalchemy/test_enginefacade.py +++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py @@ -1842,21 +1842,17 @@ class ConfigOptionsTest(oslo_test_base.BaseTestCase): class TestTransactionFactoryCallback(oslo_test_base.BaseTestCase): - def setUp(self): - super(TestTransactionFactoryCallback, self).setUp() - self.callback = mock.Mock() - self.factory = enginefacade._TransactionFactory() - cfg.CONF.register_opts(options.database_opts, 'database') - self.factory._facade_cfg['on_engine_create'] = [self.callback] - - def test__setup_for_connection_called_with_profiler(self): - engine_args = self.factory._engine_args_for_conf(cfg.CONF) - maker_args = self.factory._maker_args_for_conf(cfg.CONF) - with mock.patch.object(oslo_engines, "create_engine"), \ - mock.patch.object(orm, "get_maker"): - engine, sessionmaker = self.factory._setup_for_connection( - mock.Mock(return_value='test_url'), engine_args, maker_args) - self.callback.assert_called_with(engine) + def test_setup_for_connection_called_with_profiler(self): + hook = mock.Mock() + context_manager = enginefacade.transaction_context() + context_manager.configure(connection='sqlite://', + on_engine_create=[hook]) + + @context_manager.reader + def go(context): + hook.assert_called_once_with(context.session.bind) + + go(oslo_context.RequestContext()) def test_context_manager_append_on_engine_create(self): context_manager = enginefacade.transaction_context(