summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2014-02-27 18:58:02 +0200
committerRoman Podoliaka <rpodolyaka@mirantis.com>2014-02-27 18:58:02 +0200
commitbbe3a0fb0b625f0f8d82f6d39d75c6c90737ad02 (patch)
treed50e63af4ee5a66cfd74c9a28720a45c1c1db189 /tests
parent2f2f4ab48a7a63375d887163c7219586d3eb15ce (diff)
downloadoslo-db-bbe3a0fb0b625f0f8d82f6d39d75c6c90737ad02.tar.gz
Add from_config() method to EngineFacade
Add a helper that allows to create an EngineFacade instance given an oslo.config instance. This helper is completely optional, but it was requested by a few people syncing the latest oslo.db code to target projects. Note, that oslo.config is mocked in tests, so oslo.db still has no runtime dependency on oslo.config. Blueprint: oslo-db-lib Change-Id: Icab476386b859be0b0e984a94cbfcf3d581ab6d2
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/db/sqlalchemy/test_sqlalchemy.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/unit/db/sqlalchemy/test_sqlalchemy.py b/tests/unit/db/sqlalchemy/test_sqlalchemy.py
index be04a41..b3dbfe0 100644
--- a/tests/unit/db/sqlalchemy/test_sqlalchemy.py
+++ b/tests/unit/db/sqlalchemy/test_sqlalchemy.py
@@ -345,6 +345,39 @@ class EngineFacadeTestCase(test.BaseTestCase):
self.assertFalse(ses.autocommit)
self.assertTrue(ses.expire_on_commit)
+ @mock.patch('openstack.common.db.sqlalchemy.session.get_maker')
+ @mock.patch('openstack.common.db.sqlalchemy.session.create_engine')
+ def test_creation_from_config(self, create_engine, get_maker):
+ conf = mock.MagicMock()
+ conf.database.items.return_value = [
+ ('connection_debug', 100),
+ ('max_pool_size', 10)
+ ]
+
+ session.EngineFacade.from_config('sqlite:///:memory:', conf,
+ autocommit=False,
+ expire_on_commit=True,
+ mysql_sql_mode='TRADITIONAL')
+
+ conf.database.items.assert_called_once_with()
+ create_engine.assert_called_once_with(
+ sql_connection='sqlite:///:memory:',
+ connection_debug=100,
+ max_pool_size=10,
+ mysql_sql_mode='TRADITIONAL',
+ sqlite_fk=False,
+ idle_timeout=mock.ANY,
+ retry_interval=mock.ANY,
+ max_retries=mock.ANY,
+ max_overflow=mock.ANY,
+ connection_trace=mock.ANY,
+ sqlite_synchronous=mock.ANY,
+ pool_timeout=mock.ANY,
+ )
+ get_maker.assert_called_once_with(engine=create_engine(),
+ autocommit=False,
+ expire_on_commit=True)
+
class SetSQLModeTestCase(test_log.LogTestBase):
def setUp(self):