From 602ce2481cc800bf857a3ea36bfeba6dd308fe85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Sun, 16 Oct 2022 16:06:47 +0200 Subject: [PATCH] rename function --- src/caoscrawler/crawl.py | 17 +++++------------ unittests/test_tool.py | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/caoscrawler/crawl.py b/src/caoscrawler/crawl.py index 69de43ce..9509680a 100644 --- a/src/caoscrawler/crawl.py +++ b/src/caoscrawler/crawl.py @@ -480,7 +480,7 @@ class Crawler(object): return self._synchronize(self.target_data, commit_changes, unique_names=unique_names) - def can_be_checked_externally(self, record: db.Record): + def references_entities_without_ids(self, record: db.Record): """ Returns False if there is at least one property in record which: a) is a reference property AND @@ -495,17 +495,10 @@ class Crawler(object): if isinstance(p.value, list): for el in p.value: if isinstance(el, db.Entity) and el.id is None: - return False - # TODO: please check! - # I removed the condition "is_reference", because the datatype field - # that is checked within this function is not always present for references - # parsed from the file structure. We have to rely on the condition, that - # if a property value is of type entity, it can be assumed to be a reference. - # elif (is_reference(p) and isinstance(p.value, db.Entity) - # and p.value.id is None): + return True elif isinstance(p.value, db.Entity) and p.value.id is None: - return False - return True + return True + return False def create_flat_list(self, ent_list: List[db.Entity], flat: List[db.Entity]): """ @@ -689,7 +682,7 @@ class Crawler(object): del flat[i] # all identifying references need to be IDs that exist on the remote server - elif self.can_be_checked_externally(record): + elif not self.references_entities_without_ids(record): # Check remotely # TODO: remove deepcopy? diff --git a/unittests/test_tool.py b/unittests/test_tool.py index 65220cb6..3a525d56 100755 --- a/unittests/test_tool.py +++ b/unittests/test_tool.py @@ -392,8 +392,8 @@ def test_split_into_inserts_and_updates_single(crawler_mocked_identifiable_retri assert crawler.get_identified_record_from_local_cache(entlist[0]) is None assert crawler.get_identified_record_from_local_cache(entlist[1]) is None - assert crawler.can_be_checked_externally(entlist[0]) - assert crawler.can_be_checked_externally(entlist[1]) + assert not crawler.references_entities_without_ids(entlist[0]) + assert not crawler.references_entities_without_ids(entlist[1]) assert crawler.identifiableAdapter.retrieve_identified_record_for_record( entlist[0]).id == 1111 assert crawler.identifiableAdapter.retrieve_identified_record_for_record( @@ -539,22 +539,22 @@ def test_all_references_are_existing_already(crawler): def test_can_be_checked_externally(crawler, ident): - assert crawler.can_be_checked_externally( + assert not crawler.references_entities_without_ids( db.Record().add_parent("Person").add_property('last_name', 123).add_property('first_name', 123)) # id and rec with id - assert crawler.can_be_checked_externally(db.Record().add_parent("Person") - .add_property('first_name', 123) - .add_property('last_name', db.Record(id=123))) + assert not crawler.references_entities_without_ids(db.Record().add_parent("Person") + .add_property('first_name', 123) + .add_property('last_name', db.Record(id=123))) # id and rec with id and one unneeded prop - assert crawler.can_be_checked_externally(db.Record().add_parent("Person") - .add_property('first_name', 123) - .add_property('stuff', db.Record()) - .add_property('last_name', db.Record(id=123))) + assert not crawler.references_entities_without_ids(db.Record().add_parent("Person") + .add_property('first_name', 123) + .add_property('stuff', db.Record()) + .add_property('last_name', db.Record(id=123))) # one identifying prop is missing - assert not crawler.can_be_checked_externally(db.Record().add_parent("Person") - .add_property('first_name', 123) - .add_property('last_name', db.Record())) + assert crawler.references_entities_without_ids(db.Record().add_parent("Person") + .add_property('first_name', 123) + .add_property('last_name', db.Record())) def test_replace_entities_with_ids(crawler): -- GitLab