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

works

parent 92af1eb8
No related branches found
No related tags found
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
Pipeline #50091 passed with warnings
...@@ -88,7 +88,7 @@ class SyncGraph(): ...@@ -88,7 +88,7 @@ class SyncGraph():
) = self._create_reference_mapping(self.nodes) ) = self._create_reference_mapping(self.nodes)
self._mark_entities_with_path_or_id() self._mark_entities_with_path_or_id()
for node in self.nodes: for node in list(self.nodes):
try: try:
identifiable = self.identifiableAdapter.get_identifiable( identifiable = self.identifiableAdapter.get_identifiable(
node, self.backward_id_referenced_by[node.uuid]) node, self.backward_id_referenced_by[node.uuid])
...@@ -106,6 +106,8 @@ class SyncGraph(): ...@@ -106,6 +106,8 @@ class SyncGraph():
if node_id is None: if node_id is None:
node_id = self._get_new_id() node_id = self._get_new_id()
node.id = node_id node.id = node_id
for el in node.other:
el.id = node_id
if node_id in self._id_look_up: if node_id in self._id_look_up:
self._merge_into(node, self._id_look_up[node.id]) self._merge_into(node, self._id_look_up[node.id])
else: else:
...@@ -358,8 +360,10 @@ class SyncGraph(): ...@@ -358,8 +360,10 @@ class SyncGraph():
if isinstance(v, SyncNode): if isinstance(v, SyncNode):
forward_references[node.uuid].add(v) forward_references[node.uuid].add(v)
backward_references[v.uuid].add(node) backward_references[v.uuid].add(node)
if len([el.name for el in node.registered_identifiable.properties if if (node.registered_identifiable is not None
el.name == p.name]) > 0: and len([el.name
for el in node.registered_identifiable.properties if
el.name == p.name]) > 0):
forward_id_references[node.uuid].add(v) forward_id_references[node.uuid].add(v)
backward_id_references[v.uuid].add(node) backward_id_references[v.uuid].add(node)
if (v.registered_identifiable is not None and if (v.registered_identifiable is not None and
...@@ -418,6 +422,9 @@ class SyncGraph(): ...@@ -418,6 +422,9 @@ class SyncGraph():
assert source is not target assert source is not target
target.update(source) target.update(source)
target.other.append(source) target.other.append(source)
target.other.extend(source.other)
for el in target.other:
el.id = target.id
# update reference mappings # update reference mappings
for node in self.forward_references.pop(source.uuid): for node in self.forward_references.pop(source.uuid):
......
...@@ -455,7 +455,7 @@ def test_set_id_of_node(simple_adapter): ...@@ -455,7 +455,7 @@ def test_set_id_of_node(simple_adapter):
@patch("caoscrawler.sync_graph.cached_get_entity_by", @patch("caoscrawler.sync_graph.cached_get_entity_by",
new=Mock(side_effect=mock_get_entity_by)) new=Mock(side_effect=mock_get_entity_by))
def test_merging(): def test_merging(simple_adapter):
# identifying information can be given at various locations in the hierachical tree # identifying information can be given at various locations in the hierachical tree
# test whether an object is correctly combined for all cases # test whether an object is correctly combined for all cases
ident_adapter = CaosDBIdentifiableAdapter() ident_adapter = CaosDBIdentifiableAdapter()
...@@ -515,6 +515,26 @@ def test_merging(): ...@@ -515,6 +515,26 @@ def test_merging():
assert 101 == st.nodes[0].id assert 101 == st.nodes[0].id
def test_something(simple_adapter):
a = db.Record().add_parent("RT3").add_property('a', value=1)
entlist = [
a,
db.Record().add_parent("RT3").add_property('a', value=1),
db.Record().add_parent("RT3").add_property('a', value=1),
db.Record().add_parent("RT3").add_property('a', value=1),
db.Record().add_parent("RT3").add_property('a', value=1),
db.Record().add_parent("RT4").add_property('RT3', value=a),
db.Record().add_parent("RT3").add_property('a', value=1),
db.Record().add_parent("RT3").add_property('a', value=1)]
st = SyncGraph(entlist, simple_adapter)
assert len(st.nodes) == 2
assert len(st.unchecked) == 2
assert 'RT4' == st.nodes[1].parents[0].name
st.set_id_of_node(st.nodes[0], 101)
b_prop = st.nodes[1].properties[0].value
assert b_prop.id == 101
def test_sync_node(): def test_sync_node():
# initialization # initialization
rec = (db.Record(id=101, name='101') rec = (db.Record(id=101, name='101')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment