Commit ae70e6fa authored by Etienne Lessard's avatar Etienne Lessard

use config.DB_URI directly in db_manager

parent 9a8c0c8f
......@@ -24,14 +24,12 @@ from sqlalchemy.exc import InvalidRequestError, OperationalError
logger = logging.getLogger(__name__)
_DB_URI = config.DB_URI
dbsession = None
def connect():
logger.debug('Connecting to database: %s' % _DB_URI)
engine = create_engine(_DB_URI, echo=config.SQL_DEBUG)
logger.debug('Connecting to database: %s' % config.DB_URI)
engine = create_engine(config.DB_URI, echo=config.SQL_DEBUG)
Session = sessionmaker(bind=engine)
return Session()
......
......@@ -2,6 +2,7 @@
import unittest
from mock import patch, Mock, ANY
from xivo_dao.helpers import config
from xivo_dao.helpers import db_manager
from sqlalchemy.exc import InvalidRequestError
......@@ -14,8 +15,6 @@ class TestDBManager(unittest.TestCase):
@patch('xivo_dao.helpers.db_manager.create_engine')
@patch('xivo_dao.helpers.db_manager.sessionmaker')
def test_connect(self, sessionmaker_mock, create_engine_mock):
db_manager._DB_URI = "testuri"
engine_mock = Mock()
sessionmaker_value = Mock()
session_mock = Mock()
......@@ -26,7 +25,7 @@ class TestDBManager(unittest.TestCase):
result = db_manager.connect()
create_engine_mock.assert_called_once_with("testuri", echo=ANY)
create_engine_mock.assert_called_once_with(config.DB_URI, echo=ANY)
sessionmaker_mock.assert_called_once_with(bind=engine_mock)
self.assertEquals(result, session_mock)
......
......@@ -20,6 +20,7 @@ import logging
from xivo_dao.alchemy.base import Base
from sqlalchemy.schema import MetaData
from xivo_dao.helpers import config
from xivo_dao.helpers import db_manager
logger = logging.getLogger(__name__)
......@@ -30,7 +31,7 @@ class DAOTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
logger.debug("Connecting to database")
db_manager._DB_URI = 'postgresql://asterisk:asterisk@localhost/asterisktest'
config.DB_URI = 'postgresql://asterisk:asterisk@localhost/asterisktest'
cls.session = db_manager.session()
cls.engine = cls.session.get_bind()
logger.debug("Connected to database")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment