Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
8e6b4fba
Commit
8e6b4fba
authored
2 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
ENH: include authorization of inserts
parent
9039075d
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!53
Release 0.1
,
!34
F insert auth
Pipeline
#28061
failed
2 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
integrationtests/basic_example/test.py
+24
-1
24 additions, 1 deletion
integrationtests/basic_example/test.py
src/caoscrawler/crawl.py
+12
-11
12 additions, 11 deletions
src/caoscrawler/crawl.py
unittests/test_tool.py
+2
-4
2 additions, 4 deletions
unittests/test_tool.py
with
38 additions
and
16 deletions
integrationtests/basic_example/test.py
+
24
−
1
View file @
8e6b4fba
...
@@ -28,12 +28,13 @@
...
@@ -28,12 +28,13 @@
module description
module description
"""
"""
from
caosadvancedtools.crawler
import
Crawler
as
OldCrawler
import
os
import
os
from
caosdb
import
EmptyUniqueQueryError
from
caosdb
import
EmptyUniqueQueryError
import
argparse
import
argparse
import
sys
import
sys
from
argparse
import
RawTextHelpFormatter
from
argparse
import
RawTextHelpFormatter
from
caoscrawler
import
Crawler
from
caoscrawler
import
Crawler
,
SecurityMode
import
caosdb
as
db
import
caosdb
as
db
from
caoscrawler.identifiable_adapters
import
CaosDBIdentifiableAdapter
from
caoscrawler.identifiable_adapters
import
CaosDBIdentifiableAdapter
import
pytest
import
pytest
...
@@ -170,6 +171,28 @@ def test_insertion(clear_database, usemodel, ident, crawler):
...
@@ -170,6 +171,28 @@ def test_insertion(clear_database, usemodel, ident, crawler):
assert
len
(
ups
)
==
0
assert
len
(
ups
)
==
0
def
test_insert_auth
(
clear_database
,
usemodel
,
ident
,
crawler
):
ins
,
ups
=
crawler
.
synchronize
()
# Do a second run on the same data, there should a new insert:
cr
=
Crawler
(
debug
=
True
,
identifiableAdapter
=
ident
,
securityMode
=
SecurityMode
.
RETRIEVE
)
crawl_standard_test_directory
(
cr
,
"
example_insert
"
)
assert
len
(
cr
.
target_data
)
==
3
ins
,
ups
=
cr
.
synchronize
()
assert
len
(
ins
)
==
1
assert
not
ins
[
0
].
is_valid
()
nins
,
nups
=
OldCrawler
.
update_authorized_changes
(
cr
.
run_id
)
assert
nins
==
1
# Do it again to check whether nothing is changed:
cr
=
Crawler
(
debug
=
True
,
identifiableAdapter
=
ident
)
crawl_standard_test_directory
(
cr
,
"
example_insert
"
)
assert
len
(
cr
.
target_data
)
==
3
ins
,
ups
=
cr
.
synchronize
()
assert
len
(
ins
)
==
0
assert
len
(
ups
)
==
0
def
test_insertion_and_update
(
clear_database
,
usemodel
,
ident
,
crawler
):
def
test_insertion_and_update
(
clear_database
,
usemodel
,
ident
,
crawler
):
ins
,
ups
=
crawler
.
synchronize
()
ins
,
ups
=
crawler
.
synchronize
()
...
...
This diff is collapsed.
Click to expand it.
src/caoscrawler/crawl.py
+
12
−
11
View file @
8e6b4fba
...
@@ -777,12 +777,8 @@ class Crawler(object):
...
@@ -777,12 +777,8 @@ 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
:
update_cache
=
UpdateCache
()
raise
RuntimeError
(
"
You must not insert Entities since the Crawler was startet
"
update_cache
.
insert
(
to_be_inserted
,
run_id
,
insert
=
True
)
"
with RETRIEVE only mode.
"
)
# Caching forbidden inserts is currently not implemented
# cache = Cache()
# cache.insert(to_be_inserted, run_id)
@staticmethod
@staticmethod
def
set_ids_and_datatype_of_parents_and_properties
(
rec_list
):
def
set_ids_and_datatype_of_parents_and_properties
(
rec_list
):
...
@@ -845,16 +841,20 @@ class Crawler(object):
...
@@ -845,16 +841,20 @@ class Crawler(object):
self
.
execute_updates_in_list
(
to_be_updated
,
self
.
securityMode
,
self
.
run_id
)
self
.
execute_updates_in_list
(
to_be_updated
,
self
.
securityMode
,
self
.
run_id
)
update_cache
=
UpdateCache
()
update_cache
=
UpdateCache
()
pending_changes
=
update_cache
.
get_updates
(
self
.
run_id
)
pending_inserts
=
update_cache
.
get_inserts
(
self
.
run_id
)
if
pending_inserts
:
Crawler
.
inform_about_pending_changes
(
pending_inserts
,
self
.
run_id
,
self
.
crawled_directory
)
if
pending_changes
:
pending_updates
=
update_cache
.
get_updates
(
self
.
run_id
)
if
pending_updates
:
Crawler
.
inform_about_pending_changes
(
Crawler
.
inform_about_pending_changes
(
pending_
chang
es
,
self
.
run_id
,
self
.
crawled_directory
)
pending_
updat
es
,
self
.
run_id
,
self
.
crawled_directory
)
return
(
to_be_inserted
,
to_be_updated
)
return
(
to_be_inserted
,
to_be_updated
)
@staticmethod
@staticmethod
def
inform_about_pending_changes
(
pending_changes
,
run_id
,
path
):
def
inform_about_pending_changes
(
pending_changes
,
run_id
,
path
,
inserts
=
False
):
# Sending an Email with a link to a form to authorize updates is
# Sending an Email with a link to a form to authorize updates is
# only done in SSS mode
# only done in SSS mode
...
@@ -870,7 +870,8 @@ UNAUTHORIZED UPDATE ({} of {}):
...
@@ -870,7 +870,8 @@ UNAUTHORIZED UPDATE ({} of {}):
____________________
\n
"""
.
format
(
i
+
1
,
len
(
pending_changes
))
+
str
(
el
[
3
]))
____________________
\n
"""
.
format
(
i
+
1
,
len
(
pending_changes
))
+
str
(
el
[
3
]))
logger
.
info
(
"
There were unauthorized changes (see above). An
"
logger
.
info
(
"
There were unauthorized changes (see above). An
"
"
email was sent to the curator.
\n
"
"
email was sent to the curator.
\n
"
"
You can authorize the updates by invoking the crawler
"
"
You can authorize the
"
+
(
"
inserts
"
if
inserts
else
"
updates
"
)
+
"
by invoking the crawler
"
"
with the run id: {rid}
\n
"
.
format
(
rid
=
run_id
))
"
with the run id: {rid}
\n
"
.
format
(
rid
=
run_id
))
@staticmethod
@staticmethod
...
...
This diff is collapsed.
Click to expand it.
unittests/test_tool.py
+
2
−
4
View file @
8e6b4fba
...
@@ -605,13 +605,11 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
...
@@ -605,13 +605,11 @@ def test_security_mode(updateCacheMock, upmock, insmock, ident):
# remove one element
# remove one element
del
ident
.
_records
[
-
1
]
del
ident
.
_records
[
-
1
]
# insert forbidden
# insert forbidden
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
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
()
# as long as caching of inserts is not implemented this is not called
assert
updateCacheMock
.
call_count
==
1
updateCacheMock
.
assert_not_called
()
# reset counts
# reset counts
reset_mocks
([
updateCacheMock
,
insmock
,
upmock
])
reset_mocks
([
updateCacheMock
,
insmock
,
upmock
])
# restore original ident
# restore original ident
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment