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

FIX: setting of id

parent 38483610
Branches
Tags
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
Pipeline #51822 failed
...@@ -68,15 +68,17 @@ class SyncNode(db.Entity): ...@@ -68,15 +68,17 @@ class SyncNode(db.Entity):
""" """
def __init__( 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 # db.Entity properties
self.id: Union[int, TempID, str] = entity.id
self.role = entity.role self.role = entity.role
self.path = entity.path self.path = entity.path
self.file = entity.file self.file = entity.file
self.name = entity.name
self.description = entity.description
self.parents = _ParentList().extend(entity.parents) self.parents = _ParentList().extend(entity.parents)
self.properties = _Properties().extend(entity.properties) self.properties = _Properties().extend(entity.properties)
self._check_for_multiproperties() self._check_for_multiproperties()
...@@ -193,6 +195,7 @@ class SyncNode(db.Entity): ...@@ -193,6 +195,7 @@ class SyncNode(db.Entity):
{ {
"id": self.id, "id": self.id,
"name": self.name, "name": self.name,
"path": self.path,
"parents": [el.name for el in self.parents], "parents": [el.name for el in self.parents],
}, },
allow_unicode=True, allow_unicode=True,
...@@ -211,6 +214,7 @@ class SyncNode(db.Entity): ...@@ -211,6 +214,7 @@ class SyncNode(db.Entity):
{ {
"id": el.id, "id": el.id,
"name": el.name, "name": el.name,
"path": el.path,
"parents": [e.name for e in el.parents], "parents": [e.name for e in el.parents],
} }
) )
......
...@@ -29,6 +29,7 @@ test identifiable_adapters module ...@@ -29,6 +29,7 @@ test identifiable_adapters module
import os import os
from datetime import datetime from datetime import datetime
from unittest.mock import MagicMock, Mock, patch
from pathlib import Path from pathlib import Path
import caosdb as db import caosdb as db
...@@ -249,6 +250,8 @@ def test_retrieve_identified_record_for_identifiable(): ...@@ -249,6 +250,8 @@ def test_retrieve_identified_record_for_identifiable():
assert r_cur.description == idr_r1.description 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(): def test_referencing_entity_has_appropriate_type():
dummy = db.Record().add_parent("A") dummy = db.Record().add_parent("A")
registered_identifiable = db.RecordType() registered_identifiable = db.RecordType()
......
...@@ -100,7 +100,8 @@ def test_create_flat_list(): ...@@ -100,7 +100,8 @@ def test_create_flat_list():
assert d in flat assert d in flat
@patch("caoscrawler.identifiable_adapters.get_children_of_rt",
new=Mock(side_effect=lambda x: [x]))
def test_create_reference_mapping(): def test_create_reference_mapping():
a = SyncNode(db.Record().add_parent("RT1"), a = SyncNode(db.Record().add_parent("RT1"),
db.RecordType().add_property("is_referenced_by", ["RT2"])) db.RecordType().add_property("is_referenced_by", ["RT2"]))
...@@ -201,6 +202,8 @@ def test_SyncGraph_init(): ...@@ -201,6 +202,8 @@ def test_SyncGraph_init():
assert el.identifiable is not None or el.id is not None 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): def test_merge_into_trivial(simple_adapter):
# simplest case: a -> c # simplest case: a -> c
# b # b
...@@ -277,6 +280,8 @@ def test_merge_into_trivial(simple_adapter): ...@@ -277,6 +280,8 @@ def test_merge_into_trivial(simple_adapter):
assert se_b in st.backward_references_backref[id(se_c)] 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): def test_merge_into_simple(simple_adapter):
# simple case: a -> c <- b (a & b reference c; a & b have the same target record) # simple case: a -> c <- b (a & b reference c; a & b have the same target record)
c = db.Record(name='c').add_parent("RT2") c = db.Record(name='c').add_parent("RT2")
...@@ -356,6 +361,8 @@ def test_merge_into_simple(simple_adapter): ...@@ -356,6 +361,8 @@ def test_merge_into_simple(simple_adapter):
se_b in st.backward_references_backref[id(se_c)] 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(): def test_backward_references_backref():
# We use the reference as identifying reference in both directions. Thus the map is the same # 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 # for all three categories: references, id_references and id_referenced_by
...@@ -372,6 +379,8 @@ def test_backward_references_backref(): ...@@ -372,6 +379,8 @@ def test_backward_references_backref():
assert st.nodes[1] in st.backward_references_backref[id(st.nodes[0])] 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): def test_set_id_of_node(simple_adapter):
# setting the id should lead to the node being marked as existing # setting the id should lead to the node being marked as existing
ent_list = [db.Record(name='a').add_parent("RT5")] ent_list = [db.Record(name='a').add_parent("RT5")]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment