Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
f9e8c8cc
Commit
f9e8c8cc
authored
Feb 05, 2020
by
Markus Scheidgen
Browse files
Improved admin uploads cli test, added proc reset function.
parent
cba76e53
Changes
3
Hide whitespace changes
Inline
Side-by-side
nomad/cli/admin/uploads.py
View file @
f9e8c8cc
...
...
@@ -121,15 +121,15 @@ def ls(ctx, uploads, calculations, ids, json):
@
uploads
.
command
(
help
=
'Change the owner of the upload and all its calcs.'
)
@
click
.
argument
(
'
EMAIL
'
,
nargs
=
1
)
@
click
.
argument
(
'
USERNAME
'
,
nargs
=
1
)
@
click
.
argument
(
'UPLOADS'
,
nargs
=-
1
)
@
click
.
pass_context
def
chown
(
ctx
,
email
,
uploads
):
def
chown
(
ctx
,
username
,
uploads
):
_
,
uploads
=
query_uploads
(
ctx
,
uploads
)
print
(
'%d uploads selected, changing its owner ...'
%
uploads
.
count
())
user
=
datamodel
.
User
.
get
(
email
=
email
)
user
=
datamodel
.
User
.
get
(
username
=
username
)
for
upload
in
uploads
:
upload
.
user_id
=
user
.
user_id
...
...
@@ -139,14 +139,38 @@ def chown(ctx, email, uploads):
def
create_update
(
calc
):
return
UpdateOne
(
{
'_id'
:
calc
.
calc_id
},
{
'$set'
:
{
'metadata.uploader'
:
user
.
to_popo
()
}})
{
'$set'
:
{
'metadata.uploader'
:
user
.
user_id
}})
proc
.
Calc
.
_get_collection
().
bulk_write
([
create_update
(
calc
)
for
calc
in
calcs
])
upload
.
save
()
upload_with_metadata
=
upload
.
to_upload_with_metadata
()
calcs
=
upload_with_metadata
.
calcs
search
.
publish
(
calcs
)
search
.
index_all
(
calcs
,
do_refresh
=
False
)
search
.
refresh
()
@
uploads
.
command
(
help
=
'Change the owner of the upload and all its calcs.'
)
@
click
.
argument
(
'UPLOADS'
,
nargs
=-
1
)
@
click
.
option
(
'--with-calcs'
,
is_flag
=
True
,
help
=
'Also reset all calculations.'
)
@
click
.
pass_context
def
reset
(
ctx
,
uploads
,
with_calcs
):
_
,
uploads
=
query_uploads
(
ctx
,
uploads
)
uploads_count
=
uploads
.
count
()
print
(
'%d uploads selected, resetting their processing ...'
%
uploads_count
)
i
=
0
for
upload
in
uploads
:
if
with_calcs
:
for
calc
in
proc
.
Calc
.
objects
(
upload_id
=
upload
.
upload_id
):
calc
.
reset
()
calc
.
save
()
upload
.
reset
()
upload
.
save
()
i
+=
1
print
(
'resetted %d of %d uploads'
%
(
i
,
uploads_count
))
@
uploads
.
command
(
help
=
'(Re-)index all calcs of the given uploads.'
)
...
...
tests/conftest.py
View file @
f9e8c8cc
...
...
@@ -236,7 +236,7 @@ class KeycloakMock:
for
user_id
,
user_values
in
self
.
users
.
items
():
if
user_values
[
'username'
]
==
username
:
return
User
(
**
user_values
)
raise
KeyError
(
'Only test user
email
s are recognized'
)
raise
KeyError
(
'Only test user
username
s are recognized'
)
else
:
assert
False
,
'no token based get_user during tests'
...
...
tests/test_cli.py
View file @
f9e8c8cc
...
...
@@ -181,6 +181,37 @@ class TestAdminUploads:
with
upload_files
.
archive_file
(
calc
.
calc_id
)
as
f
:
f
.
read
()
def
test_chown
(
self
,
published
,
test_user
,
other_test_user
):
upload_id
=
published
.
upload_id
calc
=
Calc
.
objects
(
upload_id
=
upload_id
).
first
()
assert
calc
.
metadata
[
'uploader'
]
==
other_test_user
.
user_id
result
=
click
.
testing
.
CliRunner
().
invoke
(
cli
,
[
'admin'
,
'uploads'
,
'chown'
,
test_user
.
username
,
upload_id
],
catch_exceptions
=
False
,
obj
=
utils
.
POPO
())
assert
result
.
exit_code
==
0
assert
'changing'
in
result
.
stdout
upload
=
Upload
.
objects
(
upload_id
=
upload_id
).
first
()
calc
.
reload
()
assert
upload
.
user_id
==
test_user
.
user_id
assert
calc
.
metadata
[
'uploader'
]
==
test_user
.
user_id
def
test_reset
(
self
,
non_empty_processed
):
upload_id
=
non_empty_processed
.
upload_id
result
=
click
.
testing
.
CliRunner
().
invoke
(
cli
,
[
'admin'
,
'uploads'
,
'reset'
,
'--with-calcs'
,
upload_id
],
catch_exceptions
=
False
,
obj
=
utils
.
POPO
())
assert
result
.
exit_code
==
0
assert
'reset'
in
result
.
stdout
upload
=
Upload
.
objects
(
upload_id
=
upload_id
).
first
()
calc
=
Calc
.
objects
(
upload_id
=
upload_id
).
first
()
assert
upload
.
tasks_status
==
proc
.
PENDING
assert
calc
.
tasks_status
==
proc
.
PENDING
@
pytest
.
mark
.
usefixtures
(
'reset_config'
)
class
TestClient
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment