From f08bd180e254e17ee58869466c541cbf4802412f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Thu, 6 Jun 2024 16:36:54 +0200
Subject: [PATCH] FIX: setting of id

---
 src/caoscrawler/sync_node.py            | 12 ++++++++----
 unittests/test_identifiable_adapters.py |  3 +++
 unittests/test_sync_graph.py            | 11 ++++++++++-
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/caoscrawler/sync_node.py b/src/caoscrawler/sync_node.py
index 0dc674ad..e20a4e96 100644
--- a/src/caoscrawler/sync_node.py
+++ b/src/caoscrawler/sync_node.py
@@ -68,15 +68,17 @@ class SyncNode(db.Entity):
     """
 
     def __init__(
-        self, entity: db.Entity, registered_identifiable: Optional[db.RecordType] = None
+        self, entity: db.Entity, registered_identifiable: Optional[db.RecordType] = None,
+        **kwargs
     ):
+        super().__init__(name=entity.name,
+                         id=entity.id,
+                         description=entity.description,
+                         **kwargs)
         # db.Entity properties
-        self.id: Union[int, TempID, str] = entity.id
         self.role = entity.role
         self.path = entity.path
         self.file = entity.file
-        self.name = entity.name
-        self.description = entity.description
         self.parents = _ParentList().extend(entity.parents)
         self.properties = _Properties().extend(entity.properties)
         self._check_for_multiproperties()
@@ -193,6 +195,7 @@ class SyncNode(db.Entity):
             {
                 "id": self.id,
                 "name": self.name,
+                "path": self.path,
                 "parents": [el.name for el in self.parents],
             },
             allow_unicode=True,
@@ -211,6 +214,7 @@ class SyncNode(db.Entity):
                         {
                             "id": el.id,
                             "name": el.name,
+                            "path": el.path,
                             "parents": [e.name for e in el.parents],
                         }
                     )
diff --git a/unittests/test_identifiable_adapters.py b/unittests/test_identifiable_adapters.py
index 3f30f798..bdcfeacb 100644
--- a/unittests/test_identifiable_adapters.py
+++ b/unittests/test_identifiable_adapters.py
@@ -29,6 +29,7 @@ test identifiable_adapters module
 
 import os
 from datetime import datetime
+from unittest.mock import MagicMock, Mock, patch
 from pathlib import Path
 
 import caosdb as db
@@ -249,6 +250,8 @@ def test_retrieve_identified_record_for_identifiable():
     assert r_cur.description == idr_r1.description
 
 
+@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
+       new=Mock(side_effect=lambda x: [x]))
 def test_referencing_entity_has_appropriate_type():
     dummy = db.Record().add_parent("A")
     registered_identifiable = db.RecordType()
diff --git a/unittests/test_sync_graph.py b/unittests/test_sync_graph.py
index 5d7363fb..2c63cb54 100644
--- a/unittests/test_sync_graph.py
+++ b/unittests/test_sync_graph.py
@@ -100,7 +100,8 @@ def test_create_flat_list():
     assert d in flat
 
 
-
+@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
+       new=Mock(side_effect=lambda x: [x]))
 def test_create_reference_mapping():
     a = SyncNode(db.Record().add_parent("RT1"),
                  db.RecordType().add_property("is_referenced_by", ["RT2"]))
@@ -201,6 +202,8 @@ def test_SyncGraph_init():
             assert el.identifiable is not None or el.id is not None
 
 
+@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
+       new=Mock(side_effect=lambda x: [x]))
 def test_merge_into_trivial(simple_adapter):
     # simplest case: a -> c
     #                b
@@ -277,6 +280,8 @@ def test_merge_into_trivial(simple_adapter):
     assert se_b in st.backward_references_backref[id(se_c)]
 
 
+@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
+       new=Mock(side_effect=lambda x: [x]))
 def test_merge_into_simple(simple_adapter):
     # simple case: a -> c <- b (a & b reference c; a & b have the same target record)
     c = db.Record(name='c').add_parent("RT2")
@@ -356,6 +361,8 @@ def test_merge_into_simple(simple_adapter):
     se_b in st.backward_references_backref[id(se_c)]
 
 
+@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
+       new=Mock(side_effect=lambda x: [x]))
 def test_backward_references_backref():
     # We use the reference as identifying reference in both directions. Thus the map is the same
     # for all three categories: references, id_references and id_referenced_by
@@ -372,6 +379,8 @@ def test_backward_references_backref():
     assert st.nodes[1] in st.backward_references_backref[id(st.nodes[0])]
 
 
+@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
+       new=Mock(side_effect=lambda x: [x]))
 def test_set_id_of_node(simple_adapter):
     # setting the id should lead to the node being marked as existing
     ent_list = [db.Record(name='a').add_parent("RT5")]
-- 
GitLab