def patch_engine(self, engine): """Patch an Engine into this manager. Replaces this manager's factory with a _TestTransactionFactory that will use the given Engine, and returns a callable that will reset the factory back to what we started with. Only works for root factories. Is intended for test suites that need to patch in alternate database configurations. """ existing_factory = self._factory if not existing_factory._started: existing_factory._start() maker = existing_factory._writer_maker maker_kwargs = existing_factory._maker_args_for_conf(cfg.CONF) maker = orm.get_maker(engine=engine, **maker_kwargs) factory = _TestTransactionFactory( engine, maker, apply_global=False, from_factory=existing_factory ) return self.patch_factory(factory)
def patch_engine(self, engine): """Patch an Engine into this manager. Replaces this manager's factory with a _TestTransactionFactory that will use the given Engine, and returns a callable that will reset the factory back to what we started with. Only works for root factories. Is intended for test suites that need to patch in alternate database configurations. """ existing_factory = self._factory if not existing_factory._started: existing_factory._start() maker = existing_factory._writer_maker maker_kwargs = existing_factory._maker_args_for_conf(cfg.CONF) maker = orm.get_maker(engine=engine, **maker_kwargs) factory = _TestTransactionFactory( engine, maker, apply_global=False, from_factory=existing_factory ) return self.patch_factory(factory)
def patch_with_engine(engine): with mock.patch.object(db, 'get_writer_session', autospec=True) as patch_w_sess, \ mock.patch.object(db, 'get_reader_session', autospec=True) as patch_r_sess: patch_w_sess.return_value = patch_r_sess.return_value = ( orm.get_maker(engine)()) yield
def _setup_for_connection( self, sql_connection, engine_kwargs, maker_kwargs): if sql_connection is None: raise exception.CantStartEngineError( "No sql_connection parameter is established") engine = engines.create_engine( sql_connection=sql_connection, **engine_kwargs) sessionmaker = orm.get_maker(engine=engine, **maker_kwargs) return engine, sessionmaker
def _setup_for_connection( self, sql_connection, engine_kwargs, maker_kwargs): if sql_connection is None: raise exception.CantStartEngineError( "No sql_connection parameter is established") engine = engines.create_engine( sql_connection=sql_connection, **engine_kwargs) sessionmaker = orm.get_maker(engine=engine, **maker_kwargs) return engine, sessionmaker