Skip to content
Snippets Groups Projects
Commit 9dc5ab5f authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

API: assure_object_is_in_list: this function does now check whether an object...

API: assure_object_is_in_list: this function does now check whether an object (not an entity) is in the list
parent 221b8179
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment