Skip to content
Snippets Groups Projects
Commit ebb5e9ec authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

FIX: caching of inserts is not implemented: adjust accordingly

parent 523ff91a
No related branches found
No related tags found
2 merge requests!53Release 0.1,!32ENH: add security levels that may prevent updates or inserts
Pipeline #26557 failed
...@@ -777,7 +777,10 @@ class Crawler(object): ...@@ -777,7 +777,10 @@ class Crawler(object):
if securityMode.value > SecurityMode.RETRIEVE.value: if securityMode.value > SecurityMode.RETRIEVE.value:
db.Container().extend(to_be_inserted).insert() db.Container().extend(to_be_inserted).insert()
elif run_id is not None: elif run_id is not None:
raise NotImplementedError("Caching forbidden inserts is currently not implemented")
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 = Cache()
# cache.insert(to_be_inserted, run_id) # cache.insert(to_be_inserted, run_id)
......
...@@ -594,7 +594,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): ...@@ -594,7 +594,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
# trivial case: nothing to do # trivial case: nothing to do
crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident) 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 assert crawler.run_id is not None
insmock.assert_not_called() insmock.assert_not_called()
upmock.assert_not_called() upmock.assert_not_called()
...@@ -604,11 +604,14 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): ...@@ -604,11 +604,14 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident) crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident)
# remove one element # remove one element
del ident._records[-1] 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 assert crawler.run_id is not None
insmock.assert_not_called() insmock.assert_not_called()
upmock.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 counts
reset_mocks([updateCacheMock, insmock, upmock]) reset_mocks([updateCacheMock, insmock, upmock])
# restore original ident # restore original ident
...@@ -618,7 +621,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): ...@@ -618,7 +621,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident) crawler = prepare_crawler_with_sec_mode(SecurityMode.RETRIEVE, ident)
# change one element # change one element
change_non_identifiable_prop(ident) change_non_identifiable_prop(ident)
insl, updl = crawler.synchronize(commit_changes=True) crawler.synchronize(commit_changes=True)
assert crawler.run_id is not None assert crawler.run_id is not None
insmock.assert_not_called() insmock.assert_not_called()
upmock.assert_not_called() upmock.assert_not_called()
...@@ -632,7 +635,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): ...@@ -632,7 +635,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
crawler = prepare_crawler_with_sec_mode(SecurityMode.INSERT, ident) crawler = prepare_crawler_with_sec_mode(SecurityMode.INSERT, ident)
# remove one element # remove one element
del ident._records[-1] del ident._records[-1]
insl, updl = crawler.synchronize(commit_changes=True) crawler.synchronize(commit_changes=True)
assert crawler.run_id is not None assert crawler.run_id is not None
insmock.assert_called_once() insmock.assert_called_once()
upmock.assert_not_called() upmock.assert_not_called()
...@@ -646,7 +649,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): ...@@ -646,7 +649,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
crawler = prepare_crawler_with_sec_mode(SecurityMode.INSERT, ident) crawler = prepare_crawler_with_sec_mode(SecurityMode.INSERT, ident)
# change one element # change one element
change_non_identifiable_prop(ident) change_non_identifiable_prop(ident)
insl, updl = crawler.synchronize(commit_changes=True) crawler.synchronize(commit_changes=True)
assert crawler.run_id is not None assert crawler.run_id is not None
insmock.assert_not_called() insmock.assert_not_called()
upmock.assert_not_called() upmock.assert_not_called()
...@@ -661,7 +664,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident): ...@@ -661,7 +664,7 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
# change two elements # change two elements
change_non_identifiable_prop(ident) change_non_identifiable_prop(ident)
change_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 assert crawler.run_id is not None
insmock.asser_called_once() insmock.asser_called_once()
upmock.assert_not_called() upmock.assert_not_called()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment