Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
5d2fbc85
Commit
5d2fbc85
authored
7 years ago
by
Ambrus Simon
Browse files
Options
Downloads
Patches
Plain Diff
add tests for /upload/reaper endpoint
parent
433a496f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/integration_tests/python/conftest.py
+16
-10
16 additions, 10 deletions
test/integration_tests/python/conftest.py
test/integration_tests/python/test_uploads.py
+89
-4
89 additions, 4 deletions
test/integration_tests/python/test_uploads.py
with
105 additions
and
14 deletions
test/integration_tests/python/conftest.py
+
16
−
10
View file @
5d2fbc85
...
...
@@ -175,6 +175,20 @@ def file_form():
return
file_form
@pytest.fixture
(
scope
=
'
session
'
)
def
merge_dict
():
def
merge_dict
(
a
,
b
):
"""
Merge two dicts into the first recursively
"""
for
key
,
value
in
b
.
iteritems
():
if
key
in
a
and
isinstance
(
a
[
key
],
dict
)
and
isinstance
(
b
[
key
],
dict
):
merge_dict
(
a
[
key
],
b
[
key
])
else
:
a
[
key
]
=
b
[
key
]
return
merge_dict
@pytest.fixture
(
scope
=
'
module
'
)
def
log
(
request
):
"""
Return logger for the test module for easy logging from tests
"""
...
...
@@ -218,7 +232,7 @@ class DataBuilder(object):
# merge any kwargs on top of the default payload
payload
=
copy
.
deepcopy
(
_default_payload
[
resource
])
merge_dict
(
payload
,
kwargs
)
_
merge_dict
(
payload
,
kwargs
)
# add missing required unique fields using randstr
# such fields are: [user._id, group._id, gear.gear.name]
...
...
@@ -306,12 +320,4 @@ class DataBuilder(object):
# as "private singletons" in the module. This seemed the least confusing.
_default_payload
=
default_payload
()
_api_db
=
api_db
()
def
merge_dict
(
a
,
b
):
"""
Merge two dicts into the first recursively
"""
for
key
,
value
in
b
.
iteritems
():
if
key
in
a
and
isinstance
(
a
[
key
],
dict
)
and
isinstance
(
b
[
key
],
dict
):
merge_dict
(
a
[
key
],
b
[
key
])
else
:
a
[
key
]
=
b
[
key
]
_merge_dict
=
merge_dict
()
This diff is collapsed.
Click to expand it.
test/integration_tests/python/test_uploads.py
+
89
−
4
View file @
5d2fbc85
import
json
import
dateutil.parser
import
pytest
# TODO switch to upload_file_form in all uid(-match)/label/reaper upload tests
# after #772 (coverage-low-hanging 3) gets merged to avoid conflict hell
@pytest.fixture
(
scope
=
'
function
'
)
def
upload_file_form
(
file_form
,
merge_dict
,
randstr
):
def
create_form
(
**
meta_override
):
prefix
=
randstr
()
names
=
(
'
project
'
,
'
subject
'
,
'
session
'
,
'
acquisition
'
,
'
unused
'
)
files
=
{
name
:
'
{}-{}.csv
'
.
format
(
prefix
,
name
)
for
name
in
names
}
meta
=
{
'
project
'
:
{
'
label
'
:
prefix
+
'
-project-label
'
,
'
files
'
:
[{
'
name
'
:
files
[
'
project
'
]}]
},
'
session
'
:
{
'
uid
'
:
prefix
+
'
-session-uid
'
,
'
label
'
:
prefix
+
'
-session-label
'
,
'
subject
'
:
{
'
code
'
:
prefix
+
'
-subject-code
'
,
'
files
'
:
[{
'
name
'
:
files
[
'
subject
'
]}]
},
'
files
'
:
[{
'
name
'
:
files
[
'
session
'
]}]
},
'
acquisition
'
:
{
'
uid
'
:
prefix
+
'
-acquisition-uid
'
,
'
label
'
:
prefix
+
'
-acquisition-label
'
,
'
files
'
:
[{
'
name
'
:
files
[
'
acquisition
'
]}]
}
}
if
meta_override
:
merge_dict
(
meta
,
meta_override
)
return
file_form
(
*
files
.
values
(),
meta
=
meta
)
return
create_form
def
test_upload_without_login
(
as_public
):
r
=
as_public
.
post
(
'
/upload/uid
'
)
assert
r
.
status_code
==
403
def
test_reaper_upload
(
data_builder
,
randstr
,
upload_file_form
,
as_admin
):
group_1
=
data_builder
.
create_group
()
prefix
=
randstr
()
project_label_1
=
prefix
+
'
-project-label-1
'
session_uid
=
prefix
+
'
-session-uid
'
# reaper-upload files to group_1/project_label_1 using session_uid
r
=
as_admin
.
post
(
'
/upload/reaper
'
,
files
=
upload_file_form
(
group
=
{
'
_id
'
:
group_1
},
project
=
{
'
label
'
:
project_label_1
},
session
=
{
'
uid
'
:
session_uid
},
))
assert
r
.
ok
# get session created by the upload
project_1
=
as_admin
.
get
(
'
/groups/
'
+
group_1
+
'
/projects
'
).
json
()[
0
][
'
_id
'
]
session
=
as_admin
.
get
(
'
/projects/
'
+
project_1
+
'
/sessions
'
).
json
()[
0
][
'
_id
'
]
assert
len
(
as_admin
.
get
(
'
/projects/
'
+
project_1
+
'
/sessions
'
).
json
())
==
1
assert
len
(
as_admin
.
get
(
'
/sessions/
'
+
session
+
'
/acquisitions
'
).
json
())
==
1
assert
len
(
as_admin
.
get
(
'
/sessions/
'
+
session
).
json
()[
'
files
'
])
==
1
# move session to group_2/project_2
group_2
=
data_builder
.
create_group
()
project_2
=
data_builder
.
create_project
(
group
=
group_2
,
label
=
prefix
+
'
-project-label-2
'
)
as_admin
.
put
(
'
/sessions/
'
+
session
,
json
=
{
'
project
'
:
project_2
})
assert
len
(
as_admin
.
get
(
'
/projects/
'
+
project_1
+
'
/sessions
'
).
json
())
==
0
assert
len
(
as_admin
.
get
(
'
/projects/
'
+
project_2
+
'
/sessions
'
).
json
())
==
1
# reaper-upload files using existing session_uid and incorrect group/project
r
=
as_admin
.
post
(
'
/upload/reaper
'
,
files
=
upload_file_form
(
group
=
{
'
_id
'
:
group_1
},
project
=
{
'
label
'
:
project_label_1
},
session
=
{
'
uid
'
:
session_uid
},
))
assert
r
.
ok
# verify no new sessions were created and that group/project was ignored
# NOTE uploaded project file is NOT stored in this scenario!
assert
len
(
as_admin
.
get
(
'
/projects/
'
+
project_1
+
'
/sessions
'
).
json
())
==
0
assert
len
(
as_admin
.
get
(
'
/projects/
'
+
project_2
+
'
/sessions
'
).
json
())
==
1
def
test_uid_upload
(
data_builder
,
file_form
,
as_admin
,
as_user
):
# verify that acquisition creation/file uploads worked
assert
len
(
as_admin
.
get
(
'
/sessions/
'
+
session
+
'
/acquisitions
'
).
json
())
==
2
assert
len
(
as_admin
.
get
(
'
/sessions/
'
+
session
).
json
()[
'
files
'
])
==
2
# clean up
data_builder
.
delete_group
(
group_1
,
recursive
=
True
)
data_builder
.
delete_group
(
group_2
,
recursive
=
True
)
def
test_uid_upload
(
data_builder
,
file_form
,
as_admin
,
as_user
,
as_public
):
group
=
data_builder
.
create_group
()
# try to uid-upload w/o logging in
r
=
as_public
.
post
(
'
/upload/uid
'
)
assert
r
.
status_code
==
403
# try to uid-upload w/o metadata
r
=
as_admin
.
post
(
'
/upload/uid
'
,
files
=
file_form
(
'
test.csv
'
))
assert
r
.
status_code
==
500
...
...
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