Commit 63887809 authored by Tomas Taraba's avatar Tomas Taraba

3438 Disassociate users from label, when label is deleted

parent cb12deab
......@@ -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,19 @@ 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))
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