Commit c5a79321 authored by Laurent Meiller's avatar Laurent Meiller 🐊

Merge branch '3395-add-confd-delete-labels-api' into 'master'

3395 add confd delete labels api

See merge request !65
parents 1436bd3a 28fad234
xivo-dao (2020.12.00) xivo-freya; urgency=medium
* Bump target version to 2020.12
* 3386 Add delete labels api
-- tmourier <[email protected]> Mon, 06 Jul 2020 14:47:46 +0200
......
......@@ -35,6 +35,17 @@ def get(label_id):
return query.first()
def create(label):
Session.add(label)
Session.flush()
return label
def delete(label):
Session.delete(label)
Session.flush()
def search(**parameters):
rows, total = label_search.search(Session, parameters)
return SearchResult(total, rows)
......@@ -16,10 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
from hamcrest import assert_that, equal_to
from xivo_dao.alchemy.labels import Labels
from xivo_dao.resources.labels import dao as label_dao
from xivo_dao.resources.utils.search import SearchResult
from xivo_dao.tests.test_dao import DAOTestCase
from xivo_dao.resources.labels import dao as label_dao
from xivo_dao.resources.user import dao as user_dao
class TestLabelExist(DAOTestCase):
......@@ -47,6 +47,15 @@ class TestLabelExist(DAOTestCase):
assert_that(result[1][0].users_count, equal_to(0))
assert_that(result, equal_to(expected))
def test_create_label(self):
props = {
'display_name': 'MyLabel',
'description': 'Any Label'
}
label = label_dao.create(Labels(**props))
expected = label_dao.get(label.id)
assert_that(label, equal_to(expected))
def test_get_all_labels_with_associated_user(self):
label_row = self.add_label()
user = self.add_user(callerid='"John Doe"')
......@@ -58,3 +67,13 @@ class TestLabelExist(DAOTestCase):
assert_that(result[1][0].users_count, equal_to(1))
assert_that(result, equal_to(expected))
def test_delete_label(self):
label_row = self.add_label()
label_dao.delete(label_row)
expected = SearchResult(total=0, items=[])
result = label_dao.search()
assert_that(result, equal_to(expected))
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