Fix SQL fixture to preserve engine facade settings

This adjusts the SqlFixture class to preserve the settings
we configure on the enginefacade transaction factory and
to actually pass our enginefacade into to the
test DatabaseResource we create.

This is necessary for unit tests to be able to use configuration
options we set on the enginefacade like the flush_on_subtransaction
flag added in I71e274d0f0199896f28daae6db71241d9b43a2f3.

Related-Bug: #1664643
Partially-Implements: blueprint enginefacade-switch
Change-Id: Idabc7b6b4174575c89c8010886c2b440de6a8e05
This commit is contained in:
Kevin Benton 2017-04-04 00:39:00 -07:00
parent 7c22311b61
commit 61d0082f9a
1 changed files with 7 additions and 5 deletions

View File

@ -99,11 +99,12 @@ class SqlFixture(fixtures.Fixture):
self.sessionmaker = session.get_maker(engine)
self.enginefacade_factory = enginefacade._TestTransactionFactory(
self.engine, self.sessionmaker, apply_global=False)
_restore_factory = db_api.context_manager._root_factory
self.enginefacade_factory = enginefacade._TestTransactionFactory(
self.engine, self.sessionmaker, from_factory=_restore_factory,
apply_global=False)
db_api.context_manager._root_factory = self.enginefacade_factory
engine = db_api.context_manager.writer.get_engine()
@ -160,7 +161,7 @@ class StaticSqlFixture(SqlFixture):
else:
cls._GLOBAL_RESOURCES = True
cls.schema_resource = provision.SchemaResource(
provision.DatabaseResource("sqlite"),
provision.DatabaseResource("sqlite", db_api.context_manager),
cls._generate_schema, teardown=False)
dependency_resources = {}
for name, resource in cls.schema_resource.resources:
@ -183,7 +184,8 @@ class StaticSqlFixtureNoSchema(SqlFixture):
return
else:
cls._GLOBAL_RESOURCES = True
cls.database_resource = provision.DatabaseResource("sqlite")
cls.database_resource = provision.DatabaseResource(
"sqlite", db_api.context_manager)
dependency_resources = {}
for name, resource in cls.database_resource.resources:
dependency_resources[name] = resource.getResource()