diff --git a/src/caoscrawler/crawl.py b/src/caoscrawler/crawl.py index 2d464019bdc689bc16ec7c097167698113cf5cc7..12942046e60512de8b37bfeafdc30a45d09ef5d8 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 7bdccbabdce2e71ddc8cf4d6c40ee033acba06b9..b86bc7b82113e2b357c6cf6fe16594a7e162ce8b 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()