From fb183efb925bec84a4939a6bffc4b43d9a082965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Fri, 22 Sep 2023 13:05:57 +0200 Subject: [PATCH] FIX test --- src/caoscrawler/identifiable_adapters.py | 9 +++++++-- unittests/test_crawler.py | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 2211ce89..d3716bb6 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -40,6 +40,12 @@ from .utils import has_parent logger = logging.getLogger(__name__) +def get_children_of_rt(rtname): + """Supply the name of a recordtype. This name and the name of all children RTs are returned in + a list""" + return [p.name for p in db.execute_query(f"FIND RECORDTYPE {givenrt}")] + + def convert_value(value: Any): """ Returns a string representation of the value that is suitable to be used in the query @@ -213,8 +219,7 @@ identifiabel, identifiable and identified record) for a Record. # separate class too if prop.name.lower() == "is_referenced_by": for givenrt in prop.value: - rt_and_children = [p.name - for p in db.execute_query(f"FIND RECORDTYPE {givenrt}")] + rt_and_children = get_children_of_rt(givenrt) found = False for rtname in rt_and_children: if (id(record) in referencing_entities diff --git a/unittests/test_crawler.py b/unittests/test_crawler.py index dc53cb09..e13bf5ea 100644 --- a/unittests/test_crawler.py +++ b/unittests/test_crawler.py @@ -607,7 +607,7 @@ def test_create_flat_list(): assert c in flat -@ pytest.fixture +@pytest.fixture def crawler_mocked_for_backref_test(): crawler = Crawler() # mock retrieval of registered identifiabls: return Record with just a parent @@ -685,6 +685,8 @@ def test_split_into_inserts_and_updates_backref(crawler_mocked_for_backref_test) assert insert[0].name == "B" +@patch("caoscrawler.identifiable_adapters.get_children_of_rt", + new=Mock(side_effect=id())) def test_split_into_inserts_and_updates_mult_backref(crawler_mocked_for_backref_test): # test whether multiple references of the same record type are correctly used crawler = crawler_mocked_for_backref_test @@ -705,6 +707,8 @@ def test_split_into_inserts_and_updates_mult_backref(crawler_mocked_for_backref_ assert len(insert) == 2 +@patch("caoscrawler.identifiable_adapters.get_children_of_rt", + new=Mock(side_effect=id())) def test_split_into_inserts_and_updates_diff_backref(crawler_mocked_for_backref_test): # test whether multiple references of the different record types are correctly used crawler = crawler_mocked_for_backref_test -- GitLab