diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 89397a6e5762fde5afebe76cb12d7dc5346b014c..b3109fc7ef8bffe0ef3b7c9f30e5774052ddd08b 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -2325,6 +2325,26 @@ class _Messages(dict): def _basic_sync(e_local, e_remote): + '''Copy all state from a one entity to another. + + This method is used to syncronize an entity with a remote (i.e. a newly + retrieved) one. + + Any entity state of the local one will be overriden. + + Parameters + ---------- + e_local : Entity + Destination of the copy. + e_local : Entity + Source of the copy. + + + Returns + ------- + e_local : Entity + The syncronized entity. + ''' if e_local is None or e_remote is None: return None if type(e_local) is Entity: @@ -2335,7 +2355,7 @@ def _basic_sync(e_local, e_remote): e_local.path = e_remote.path e_local._checksum = e_remote._checksum e_local._size = e_remote._size - e_local.datatype = e_remote.datatype # @ReservedAssignment + e_local.datatype = e_remote.datatype e_local.unit = e_remote.unit e_local.value = e_remote.value e_local.properties = e_remote.properties diff --git a/unittests/test_entity.py b/unittests/test_entity.py index 0195f24b93717dd5a8a55c2a590179dc287abda8..0a0b5efaa649423fc173ce80208854fbf3827e91 100644 --- a/unittests/test_entity.py +++ b/unittests/test_entity.py @@ -42,6 +42,8 @@ class TestEntity(unittest.TestCase): def test_instance_variables(self): entity = Entity() + self.assertTrue(hasattr(entity, "role")) + self.assertIsNone(entity.role) self.assertTrue(hasattr(entity, "id")) self.assertTrue(hasattr(entity, "name")) self.assertTrue(hasattr(entity, "description")) @@ -70,7 +72,13 @@ class TestEntity(unittest.TestCase): self.assertEqual(entity.role, "RecordType") self.assertEqual(entity.to_xml().tag, "RecordType") - def test_instanciation(self): + def test_recordtype_role(self): + entity = Property() + + self.assertEqual(entity.role, "Property") + self.assertEqual(entity.to_xml().tag, "Property") + + def test_instantiation(self): self.assertRaises(Exception, Entity()) def test_parse_role(self): @@ -83,4 +91,6 @@ class TestEntity(unittest.TestCase): parser).getroot()) self.assertEqual(entity.role, "Record") + # test whether the __role property of this object has explicitely been + # set. self.assertEqual(getattr(entity, "_Entity__role"), "Record")