diff --git a/src/caoscrawler/sync_node.py b/src/caoscrawler/sync_node.py index 0dc674ad4f6ed4eca5ce82b6b4b12a07f920b593..e20a4e963ca5c3507126f6d718ffdaeaedfe6603 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 3f30f798d43cdaa09aeef26c193302f4cc704412..bdcfeacb6dea514ad689156bf2f61e712c665a4e 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 5d7363fbf88fe4fdf7e181b03662b7907083f9a4..2c63cb54aceeaef98df36630ba0873cd62ebf7e3 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")]