Commit c7b6f71d authored by Etienne Allovon's avatar Etienne Allovon

Merge branch '3438-deleting-label-it-should-disassociate-users' into 'master'

3438 deleting label it should disassociate users

See merge request !67
parents cb12deab 4ac20538
xivo-dao (2020.14.00) xivo-freya; urgency=medium
* 3438 Disassociate users from label when the label is deleted
-- Tomas Taraba <ttaraba@avencall.com> Tue, 04 Aug 2020 16:14:32 +0200
xivo-dao (2020.13.00) xivo-freya; urgency=medium
* 3389 Create labels api
......
......@@ -49,10 +49,17 @@ def create(label):
def delete(label):
label = get(label.id)
_disassociate(label)
Session.delete(label)
Session.flush()
def _disassociate(label):
label.user_features = []
Session.flush()
def search(**parameters):
rows, total = label_search.search(Session, parameters)
return SearchResult(total, rows)
......@@ -88,3 +88,20 @@ class TestLabelExist(DAOTestCase):
result = label_dao.search()
assert_that(result, equal_to(expected))
def test_delete_associated_label(self):
label_row = self.add_label()
user = self.add_user(callerid='"John Doe"')
user.labels.append(label_row)
label_dao.delete(label_row)
expected_label = SearchResult(total=0, items=[])
result_label = label_dao.search()
result_user = user_dao.find_by_id_uuid(user.id)
assert_that(result_label, equal_to(expected_label))
assert_that(result_user.id, equal_to(user.id))
assert_that(len(result_user.labels), equal_to(0))
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