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

FIX: old tests run again

parent df463163
No related branches found
No related tags found
2 merge requests!53Release 0.1,!3F retrieve
...@@ -319,7 +319,8 @@ class Crawler(object): ...@@ -319,7 +319,8 @@ class Crawler(object):
# side effect # side effect
record.id = identified_record.id record.id = identified_record.id
to_be_updated.append(record) to_be_updated.append(record)
self.add_identified_record_to_local_cache(record) # TODO think this through
# self.add_identified_record_to_local_cache(record)
del flat[i] del flat[i]
resolved_references = True resolved_references = True
...@@ -334,13 +335,22 @@ class Crawler(object): ...@@ -334,13 +335,22 @@ class Crawler(object):
return to_be_inserted, to_be_updated return to_be_inserted, to_be_updated
def replace_entities_by_ids(self, rec: db.Record):
for el in rec.properties:
if isinstance(el.value, db.Entity):
el.value = el.value.id
elif isinstance(el.value, list):
for index, val in enumerate(el.value):
if isinstance(val, db.Entity):
el.value[index] = val.id
def remove_unnecessary_updates(self, updateList: list[db.Record]): def remove_unnecessary_updates(self, updateList: list[db.Record]):
""" """
checks whether all relevant attributes (especially Property values) are equal checks whether all relevant attributes (especially Property values) are equal
""" """
for i in reversed(range(len(updateList))): for i in reversed(range(len(updateList))):
record = updateList[i] record = updateList[i]
identifiable = self.identifiableAdapter.get_identifiable(record) identifiable = self.identifiableAdapter.retrieve_identifiable(record)
comp = compare_entities(record, identifiable) comp = compare_entities(record, identifiable)
identical = True identical = True
...@@ -392,6 +402,9 @@ class Crawler(object): ...@@ -392,6 +402,9 @@ class Crawler(object):
to_be_inserted, to_be_updated = self.split_into_inserts_and_updates(updateList) to_be_inserted, to_be_updated = self.split_into_inserts_and_updates(updateList)
# remove unnecessary updates from list # remove unnecessary updates from list
for el in to_be_updated:
self.replace_entities_by_ids(el)
self.remove_unnecessary_updates(to_be_updated) self.remove_unnecessary_updates(to_be_updated)
# TODO # TODO
......
...@@ -514,3 +514,14 @@ def test_can_be_checked_externally(crawler): ...@@ -514,3 +514,14 @@ def test_can_be_checked_externally(crawler):
assert not crawler.can_be_checked_externally(db.Record() assert not crawler.can_be_checked_externally(db.Record()
.add_property('a', 123) .add_property('a', 123)
.add_property('b', db.Record())) .add_property('b', db.Record()))
def test_replace_entities_by_ids(crawler):
a = (db.Record().add_parent("B").add_property("A", 12345)
.add_property("B", db.Record(id=12345))
.add_property("C", [db.Record(id=12345), 233324]))
crawler.replace_entities_by_ids(a)
assert a.get_property("A").value == 12345
assert a.get_property("B").value == 12345
assert a.get_property("C").value == [12345, 233324]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment