Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nomad-FAIR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
nomad-lab
nomad-FAIR
Commits
de9086b9
Commit
de9086b9
authored
6 years ago
by
Markus Scheidgen
Browse files
Options
Downloads
Patches
Plain Diff
Added API test for getting archive data.
parent
16cbf234
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
nomad/api.py
+13
-16
13 additions, 16 deletions
nomad/api.py
nomad/files.py
+4
-1
4 additions, 1 deletion
nomad/files.py
tests/test_api.py
+11
-1
11 additions, 1 deletion
tests/test_api.py
tests/test_files.py
+5
-4
5 additions, 4 deletions
tests/test_files.py
with
33 additions
and
22 deletions
nomad/api.py
+
13
−
16
View file @
de9086b9
from
flask
import
Flask
from
flask
import
Flask
,
Response
from
flask_restful
import
Resource
,
Api
,
abort
from
flask_restful
import
Resource
,
Api
,
abort
from
datetime
import
datetime
from
datetime
import
datetime
from
threading
import
Thread
from
threading
import
Thread
...
@@ -69,25 +69,22 @@ class Upload(Resource):
...
@@ -69,25 +69,22 @@ class Upload(Resource):
return
Uploads
.
_render
(
upload
),
200
return
Uploads
.
_render
(
upload
),
200
class
Calc
(
Resource
):
@app.route
(
'
/archive/<string:upload_hash>/<string:calc_hash>
'
,
methods
=
[
'
GET
'
])
def
get
(
self
,
upload_hash
,
calc_hash
):
def
get_calc
(
upload_hash
,
calc_hash
):
archive_id
=
'
%s/%s
'
%
(
upload_hash
,
calc_hash
)
archive_id
=
'
%s/%s
'
%
(
upload_hash
,
calc_hash
)
logger
=
get_logger
(
__name__
,
archive_id
=
archive_id
)
logger
=
get_logger
(
__name__
,
archive_id
=
archive_id
)
try
:
try
:
file
=
files
.
open_archive_json
(
archive_id
)
file
=
files
.
open_archive_json
(
archive_id
)
return
file
,
200
return
Response
(
file
,
mimetype
=
'
application/json
'
,
status
=
200
)
except
KeyError
:
except
KeyError
:
abort
(
404
,
message
=
'
Archive %s does not exist.
'
%
archive_id
)
abort
(
404
,
message
=
'
Archive %s does not exist.
'
%
archive_id
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
'
Exception on reading archive
'
,
exc_info
=
e
)
logger
.
error
(
'
Exception on reading archive
'
,
exc_info
=
e
)
abort
(
500
,
message
=
'
Could not read the archive.
'
)
abort
(
500
,
message
=
'
Could not read the archive.
'
)
finally
:
file
.
close
()
api
.
add_resource
(
Uploads
,
'
/uploads
'
)
api
.
add_resource
(
Uploads
,
'
/uploads
'
)
api
.
add_resource
(
Upload
,
'
/uploads/<string:upload_id>
'
)
api
.
add_resource
(
Upload
,
'
/uploads/<string:upload_id>
'
)
api
.
add_resource
(
Calc
,
'
/archive/<string:upload_hash>/<string:calc_hash>
'
)
def
start_upload_handler
(
quit
=
False
):
def
start_upload_handler
(
quit
=
False
):
...
...
This diff is collapsed.
Click to expand it.
nomad/files.py
+
4
−
1
View file @
de9086b9
...
@@ -302,4 +302,7 @@ def open_archive_json(archive_id) -> IO:
...
@@ -302,4 +302,7 @@ def open_archive_json(archive_id) -> IO:
"""
Returns a file-like to read the archive json.
"""
"""
Returns a file-like to read the archive json.
"""
# The result already is a file-like and due to the Content-Encoding metadata is
# The result already is a file-like and due to the Content-Encoding metadata is
# will automatically be un-gzipped.
# will automatically be un-gzipped.
return
_client
.
get_object
(
config
.
files
.
archive_bucket
,
archive_id
)
try
:
return
_client
.
get_object
(
config
.
files
.
archive_bucket
,
archive_id
)
except
minio
.
error
.
NoSuchKey
:
raise
KeyError
()
This diff is collapsed.
Click to expand it.
tests/test_api.py
+
11
−
1
View file @
de9086b9
...
@@ -12,7 +12,7 @@ from nomad import config, api, files
...
@@ -12,7 +12,7 @@ from nomad import config, api, files
from
tests.test_processing
import
example_files
from
tests.test_processing
import
example_files
from
tests.test_files
import
assert_exists
from
tests.test_files
import
assert_exists
# import fixtures
# import fixtures
from
tests.test_files
import
clear_files
# pylint: disable=unused-import
from
tests.test_files
import
clear_files
,
archive_id
# pylint: disable=unused-import
@pytest.fixture
@pytest.fixture
...
@@ -136,3 +136,13 @@ def test_processing(client, file):
...
@@ -136,3 +136,13 @@ def test_processing(client, file):
assert
upload
[
'
processing
'
][
'
status
'
]
==
'
SUCCESS
'
assert
upload
[
'
processing
'
][
'
status
'
]
==
'
SUCCESS
'
assert_exists
(
config
.
files
.
uploads_bucket
,
upload
[
'
id
'
])
assert_exists
(
config
.
files
.
uploads_bucket
,
upload
[
'
id
'
])
def
test_get_archive
(
client
,
archive_id
):
rv
=
client
.
get
(
'
/archive/%s
'
%
archive_id
)
assert
rv
.
status_code
==
200
def
test_get_non_existing_archive
(
client
):
rv
=
client
.
get
(
'
/archive/%s
'
%
'
doesnt/exist
'
)
assert
rv
.
status_code
==
404
This diff is collapsed.
Click to expand it.
tests/test_files.py
+
5
−
4
View file @
de9086b9
...
@@ -77,7 +77,11 @@ def upload_id(clear_files) -> Generator[str, None, None]:
...
@@ -77,7 +77,11 @@ def upload_id(clear_files) -> Generator[str, None, None]:
@pytest.fixture
(
scope
=
'
function
'
)
@pytest.fixture
(
scope
=
'
function
'
)
def
archive_id
(
clear_files
)
->
Generator
[
str
,
None
,
None
]:
def
archive_id
(
clear_files
)
->
Generator
[
str
,
None
,
None
]:
example_archive_id
=
'
__test_archive_id
'
example_archive_id
=
'
__test_upload_hash/__test_calc_hash
'
with
files
.
write_archive_json
(
example_archive_id
)
as
out
:
json
.
dump
({
'
test
'
:
'
value
'
},
out
)
yield
example_archive_id
yield
example_archive_id
...
@@ -136,9 +140,6 @@ def test_hash(uploaded_id: str):
...
@@ -136,9 +140,6 @@ def test_hash(uploaded_id: str):
def
test_archive
(
archive_id
:
str
):
def
test_archive
(
archive_id
:
str
):
with
files
.
write_archive_json
(
archive_id
)
as
out
:
json
.
dump
({
'
test
'
:
'
value
'
},
out
)
result
=
json
.
load
(
files
.
open_archive_json
(
archive_id
))
result
=
json
.
load
(
files
.
open_archive_json
(
archive_id
))
assert
'
test
'
in
result
assert
'
test
'
in
result
...
...
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