def test_dbapi_unknown_invalid_backend(self): self.config(db_backend='tests.unit.db.not_existant') dbapi = api.DBAPI() def call_it(): dbapi.api_class_call1(1, 2, kwarg1='meow') self.assertRaises(ImportError, call_it)
def test_dbapi_api_class_method_and_tpool_true(self): backend_mapping = {'test_known': 'tests.unit.db.test_api'} self.config(db_backend='test_known', dbapi_use_tpool=True) info = dict(tpool=False) orig_execute = tpool.execute def our_execute(*args, **kwargs): info['tpool'] = True return orig_execute(*args, **kwargs) self.stubs.Set(tpool, 'execute', our_execute) dbapi = api.DBAPI(backend_mapping=backend_mapping) result = dbapi.api_class_call1(1, 2, kwarg1='meow') expected = ((1, 2), {'kwarg1': 'meow'}) self.assertEqual(expected, result) self.assertTrue(info['tpool'])
# -*- coding: utf-8 -*- ''' Interface for database access ''' from oslo.config import cfg from openstack.common.db import api as db_api from openstack.common import log as logging # from forest import utils CONF = cfg.CONF _BACKEND_MAPPING = {'sqlalchemy': 'forest.db.sqlalchemy.api'} IMPL = db_api.DBAPI(backend_mapping=_BACKEND_MAPPING) LOG = logging.getLogger(__name__) def get_session(context=None): ''' Get session from context ''' return IMPL.get_session(context) def job_flow_get(context, job_flow_id): return IMPL.job_flow_get(context, job_flow_id) def job_flow_get_all(context, tenant_only=True): return IMPL.job_flow_get_all(context, tenant_only) def job_flow_get_all_by_tenant(context):
def test_dbapi_full_path_module_method(self): self.config(db_backend='tests.unit.db.test_api') dbapi = api.DBAPI() result = dbapi.api_class_call1(1, 2, kwarg1='meow') expected = ((1, 2), {'kwarg1': 'meow'}) self.assertEqual(expected, result)