diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py index 44ba253eb48241451307e25d8cb1f0b11a968444..76f7bce4244f5a6cf96f075bade8748591ef29e9 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -156,14 +156,12 @@ class AbstractCFood(object): entity.add_property(prop, value) -def assure_entity_is_in_list(entity, containing_object, property_name, +def assure_object_is_in_list(obj, containing_object, property_name, to_be_updated): """ - Checks whether `entity` is one of the values in the list property + Checks whether `obj` is one of the values in the list property `property_name` of the supplied entity containing_object`. - This check is done based on ids. - If this is the case this function returns. Otherwise the entity is added to the property `property_name` and the entity `containing_object` is added to the supplied list to_be_updated in order to indicate, that the entity @@ -179,7 +177,7 @@ def assure_entity_is_in_list(entity, containing_object, property_name, contained = False for el in current_list: - if el.id == entity.id: + if el == obj: contained = True break @@ -187,7 +185,7 @@ def assure_entity_is_in_list(entity, containing_object, property_name, if contained: return - current_list.append(entity) + current_list.append(obj) to_be_updated.append(containing_object) diff --git a/unittests/test_cfood.py b/unittests/test_cfood.py index a7d584a9531fdadeac3debba8f7ca0e969ca9fdb..2f00c1c1065d39cba3d2e6a3cc92ecc4079f7648 100644 --- a/unittests/test_cfood.py +++ b/unittests/test_cfood.py @@ -25,8 +25,8 @@ import unittest import caosdb as db -from caosadvancedtools.cfood import (AbstractCFood, assure_entity_is_in_list, - assure_has_parent) +from caosadvancedtools.cfood import (AbstractCFood, assure_has_parent, + assure_object_is_in_list) PATTERN = "h.*" @@ -52,15 +52,13 @@ class InsertionTest(unittest.TestCase): def test_contained_in_list(self): entity_with_list = db.Record() prop_name = "list_prop" - contained_entity = db.Record(id=1005) to_be_updated = [] - assure_entity_is_in_list(contained_entity, entity_with_list, prop_name, + assure_object_is_in_list(1005, entity_with_list, prop_name, to_be_updated) assert to_be_updated[0] is entity_with_list - assert (to_be_updated[0].get_property(prop_name).value[0] is - contained_entity) + assert (to_be_updated[0].get_property(prop_name).value[0] == 1005) to_be_updated = [] - assure_entity_is_in_list(contained_entity, entity_with_list, prop_name, + assure_object_is_in_list(1005, entity_with_list, prop_name, to_be_updated) assert len(to_be_updated) == 0