Commit bf1d3dba authored by Laurent Meiller's avatar Laurent Meiller

3386 WIP update ressource for labels

parent 8113cdc6
......@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, PrimaryKeyConstraint
from sqlalchemy.types import Integer, String
from sqlalchemy.types import Integer, String, Text
from xivo_dao.helpers.db_manager import Base
......@@ -29,3 +29,4 @@ class Labels(Base):
id = Column(Integer, nullable=False, autoincrement=True)
display_name = Column(String(128), nullable=False)
description = Column(Text)
# -*- coding: utf-8 -*-
# Copyright (C) 2014 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/>
# -*- coding: utf-8 -*-
# Copyright (C) 2020 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 xivo_dao.alchemy.labels import Labels
from xivo_dao.helpers.db_manager import daosession
from xivo_dao.helpers.db_manager import Session
from xivo_dao.resources.labels.search import label_search
from xivo_dao.resources.utils.search import SearchResult
@daosession
def exists(session, label_id):
query = (session.query(Labels)
.filter(Labels.id == label_id)
)
return query.count() > 0
def get(label_id):
query = Session.query(Labels).filter_by(id=label_id)
return query.first()
def search(**parameters):
rows, total = label_search.search(Session, parameters)
return SearchResult(total, rows)
# -*- coding: UTF-8 -*-
# Copyright (C) 2020 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from xivo_dao.alchemy.labels import Labels
from xivo_dao.resources.utils.search import SearchSystem
from xivo_dao.resources.utils.search import SearchConfig
config = SearchConfig(table=Labels,
columns={'id': Labels.id,
'display_name': Labels.display_name},
search=['display_name'],
default_sort='display_name')
label_search = SearchSystem(config)
# -*- coding: utf-8 -*-
# Copyright (C) 2014 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/>
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 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 xivo_dao.tests.test_dao import DAOTestCase
from xivo_dao.resources.labels import dao as label_dao
from xivo_dao.resources.utils.search import SearchResult
class TestLabelExist(DAOTestCase):
def test_given_no_label_then_returns_false(self):
result = label_dao.exists(1)
assert_that(result, equal_to(False))
def test_given_label_exists_then_return_true(self):
label_row = self.add_label()
result = label_dao.exists(label_row.id)
assert_that(result, equal_to(True))
......@@ -49,6 +49,7 @@ from xivo_dao.alchemy.func_key_type import FuncKeyType
from xivo_dao.alchemy.groupfeatures import GroupFeatures
from xivo_dao.alchemy.incall import Incall
from xivo_dao.alchemy.infos import Infos
from xivo_dao.alchemy.labels import Labels
from xivo_dao.alchemy.linefeatures import LineFeatures
from xivo_dao.alchemy.mediaserver import MediaServer
from xivo_dao.alchemy.meetmefeatures import MeetmeFeatures
......@@ -863,3 +864,11 @@ class DAOTestCase(unittest.TestCase):
def _random_name(self, length=6):
return ''.join(random.choice(string.lowercase) for _ in range(length))
def add_label(self, **kwargs):
kwargs.setdefault('id', self._generate_int())
kwargs.setdefault('display_name', self._random_name())
kwargs.setdefault('description', self._random_name(400))
label = Labels(**kwargs)
self.add_me(label)
return label
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