diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 2211ce89e495245388e7f8bbb44237109f160357..d3716bb6d0d5e35a968dc446eec305add60846db 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 dc53cb099eb5e4b225b13461176504a003f2d2ba..e13bf5ea31602eed0f52e8498a4c30e1291af727 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