From ebb5e9ec1b9734de1b198fbb2d1a2aa7989f1821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Tue, 26 Jul 2022 14:28:37 +0200 Subject: [PATCH] FIX: caching of inserts is not implemented: adjust accordingly --- src/caoscrawler/crawl.py | 9 ++++++--- unittests/test_tool.py | 17 ++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/caoscrawler/crawl.py b/src/caoscrawler/crawl.py index 2d464019..12942046 100644 --- a/src/caoscrawler/crawl.py +++ b/src/caoscrawler/crawl.py @@ -777,9 +777,12 @@ class Crawler(object): if securityMode.value > SecurityMode.RETRIEVE.value: db.Container().extend(to_be_inserted).insert() elif run_id is not None: - raise NotImplementedError("Caching forbidden inserts is currently not implemented") - #cache = Cache() - #cache.insert(to_be_inserted, run_id) + + raise RuntimeError("You must not insert Entities since the Crawler was startet " + "with RETRIEVE only mode.") + # Caching forbidden inserts is currently not implemented + # cache = Cache() + # cache.insert(to_be_inserted, run_id) @staticmethod def set_ids_and_datatype_of_parents_and_properties(rec_list): diff --git a/unittests/test_tool.py b/unittests/test_tool.py index 7bdccbab..b86bc7b8 100755 --- a/unittests/test_tool.py +++ b/unittests/test_tool.py @@ -594,7 +594,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): # trivial case: nothing to do crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident) - insl, updl = crawler.synchronize(commit_changes=True) + crawler.synchronize(commit_changes=True) assert crawler.run_id is not None insmock.assert_not_called() upmock.assert_not_called() @@ -604,11 +604,14 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident) # remove one element del ident._records[-1] - insl, updl = crawler.synchronize(commit_changes=True) + # insert forbidden + with pytest.raises(RuntimeError) as excinfo: + crawler.synchronize(commit_changes=True) assert crawler.run_id is not None insmock.assert_not_called() upmock.assert_not_called() - assert updateCacheMock.call_count == 1 + # as long as caching of inserts is not implemented this is not called + updateCacheMock.assert_not_called() # reset counts reset_mocks([updateCacheMock, insmock, upmock]) # restore original ident @@ -618,7 +621,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident) # change one element change_non_identifiable_prop(ident) - insl, updl = crawler.synchronize(commit_changes=True) + crawler.synchronize(commit_changes=True) assert crawler.run_id is not None insmock.assert_not_called() upmock.assert_not_called() @@ -632,7 +635,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): crawler = prepare_crawler_with_sec_mode(SecurityMode.INSERT, ident) # remove one element del ident._records[-1] - insl, updl = crawler.synchronize(commit_changes=True) + crawler.synchronize(commit_changes=True) assert crawler.run_id is not None insmock.assert_called_once() upmock.assert_not_called() @@ -646,7 +649,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): crawler = prepare_crawler_with_sec_mode(SecurityMode.INSERT, ident) # change one element change_non_identifiable_prop(ident) - insl, updl = crawler.synchronize(commit_changes=True) + crawler.synchronize(commit_changes=True) assert crawler.run_id is not None insmock.assert_not_called() upmock.assert_not_called() @@ -661,7 +664,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): # change two elements change_non_identifiable_prop(ident) change_identifiable_prop(ident) - insl, updl = crawler.synchronize(commit_changes=True) + crawler.synchronize(commit_changes=True) assert crawler.run_id is not None insmock.asser_called_once() upmock.assert_not_called() -- GitLab