Commit f5bf4f9e authored by Cedric Abunar's avatar Cedric Abunar

Move Base to db_manager

parent 19a60243
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
......@@ -23,7 +23,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, TEXT
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class AccessWebService(Base):
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, DateTime
from sqlalchemy.sql import func
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -39,7 +39,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2013 Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.ext.declarative import declarative_base
def todict(self):
d = {}
for c in self.__table__.columns:
value = getattr(self, c.name)
d[c.name] = value
return d
Base = declarative_base()
Base.todict = todict
Type = declarative_base()
......@@ -22,7 +22,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum, Text
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
class Callfilter(Base):
......
......@@ -22,7 +22,7 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String, Enum
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
class Callfiltermember(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import DateTime, Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CEL(Base):
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String, Text
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiContexts(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String, Text
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiDisplays(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiPreference(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, ForeignKey, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiProfile(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiProfilePreference(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiProfileService(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, Boolean
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiProfileXlet(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiService(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiXlet(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiXletLayout(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiPhoneHintsGroup(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiPresences(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class CtiStatus(Base):
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.types import Integer, String, Text, Enum
from sqlalchemy.schema import Column
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text, Enum, LargeBinary
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
class Phonebook(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
class PhonebookAddress(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
class PhonebookNumber(Base):
......
......@@ -17,7 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class PhoneFunckey(Base):
......
......@@ -33,7 +33,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import String
......
......@@ -41,7 +41,7 @@
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION
from sqlalchemy.schema import Column, ForeignKeyConstraint
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from xivo_dao.alchemy.record_campaigns import RecordCampaigns
from xivo_dao.alchemy.stat_call_on_queue import StatCallOnQueue
from xivo_dao.alchemy.stat_queue_periodic import StatQueuePeriodic
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -39,7 +39,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum
......
......@@ -20,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String, Boolean, DateTime
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class RecordCampaigns(Base):
......
......@@ -20,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import String, Integer, DateTime
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class Recordings(Base):
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -35,7 +35,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class StatAgent(Base):
......
......@@ -18,7 +18,7 @@
from sqlalchemy.schema import Column, ForeignKey, Sequence
from sqlalchemy.types import Integer, TIMESTAMP
from sqlalchemy.dialects.postgresql import INTERVAL
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class StatAgentPeriodic(Base):
......
......@@ -35,7 +35,7 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import String, TIMESTAMP, Integer, Enum
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
class StatCallOnQueue(Base):
......
......@@ -35,7 +35,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class StatQueue(Base):
......
......@@ -35,7 +35,7 @@
from sqlalchemy.schema import Column, ForeignKey, Sequence
from sqlalchemy.types import Integer, TIMESTAMP
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
class StatQueuePeriodic(Base):
......
......@@ -39,7 +39,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String, Text
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -38,7 +38,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
......
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.base import Base, Type
from xivo_dao.helpers.db_manager import Base, Type
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text, Float, Enum
......
......@@ -22,6 +22,7 @@ from sqlalchemy.engine import create_engine
from xivo_dao.helpers import config
from sqlalchemy.exc import InvalidRequestError, OperationalError
from sqlalchemy.orm import scoped_session
from sqlalchemy.ext.declarative import declarative_base
logger = logging.getLogger(__name__)
......@@ -31,6 +32,21 @@ ASTERISK_DB_NAME = 'asterisk'
XIVO_DB_NAME = 'xivo'
def todict(self):
d = {}
for c in self.__table__.columns:
value = getattr(self, c.name)
d[c.name] = value
return d
Base = declarative_base()
Base.todict = todict
Type = declarative_base()
def connect(db_name=ASTERISK_DB_NAME):
db_uri = ''
if db_name == ASTERISK_DB_NAME:
......
......@@ -17,10 +17,11 @@
import unittest
from mock import Mock
from xivo_dao.alchemy import dbconnection
from xivo_dao.helpers import dbconnection
class TestDBConnectionPool(unittest.TestCase):
def test_add_connection_creates_new_connection(self):
connection_factory = Mock()
......
......@@ -18,7 +18,7 @@
import unittest
import logging
from xivo_dao.alchemy.base import Base
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import MetaData
from xivo_dao.helpers import config
from xivo_dao.helpers import db_manager
......
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