Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
0c926116
Commit
0c926116
authored
May 02, 2020
by
Markus Scheidgen
Browse files
Fixed ineffective optimade API and its test.
parent
be4f56c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
nomad/app/api/common.py
View file @
0c926116
...
...
@@ -140,6 +140,9 @@ def add_search_parameters(request_parser):
request_parser
.
add_argument
(
'until_time'
,
type
=
lambda
x
:
rfc3339DateTime
.
parse
(
x
),
help
=
'A yyyy-MM-ddTHH:mm:ss (RFC3339) maximum entry time (e.g. upload time)'
)
request_parser
.
add_argument
(
'dft.optimade'
,
type
=
str
,
help
=
'A search query in the optimade filter language.'
)
# main search parameters
for
qualified_name
,
quantity
in
search
.
search_quantities
.
items
():
...
...
@@ -181,16 +184,16 @@ def apply_search_parameters(search_request: search.SearchRequest, args: Dict[str
until_time
=
rfc3339DateTime
.
parse
(
until_time_str
)
if
until_time_str
is
not
None
else
None
search_request
.
time_range
(
start
=
from_time
,
end
=
until_time
)
except
Exception
:
abort
(
400
,
message
=
'bad datetime format'
)
abort
(
400
,
'bad datetime format'
)
# optimade
try
:
optimade
=
args
.
get
(
'optimade'
,
None
)
optimade
=
args
.
get
(
'
dft.
optimade'
,
None
)
if
optimade
is
not
None
:
q
=
filterparser
.
parse_filter
(
optimade
)
search_request
.
query
(
q
)
except
filterparser
.
FilterException
:
abort
(
400
,
message
=
'could not parse optimade query'
)
abort
(
400
,
'could not parse optimade query'
)
# search parameter
search_request
.
search_parameters
(
**
{
...
...
tests/app/test_api.py
View file @
0c926116
...
...
@@ -1162,12 +1162,24 @@ class TestRepo():
def
test_optimade
(
self
,
api
,
non_empty_processed
,
test_user_auth
):
rv
=
api
.
get
(
'/repo/?%s'
%
urlencode
(
dict
(
owner
=
'all'
,
optimade
=
'nelements >= 1'
)
),
'/repo/?%s'
%
urlencode
(
{
'
owner
'
:
'all'
,
'dft.
optimade
'
:
'nelements >= 1'
}
),
headers
=
test_user_auth
)
assert
rv
.
status_code
==
200
data
=
json
.
loads
(
rv
.
data
)
assert
data
[
'pagination'
][
'total'
]
>
0
rv
=
api
.
get
(
'/repo/?%s'
%
urlencode
({
'owner'
:
'all'
,
'dft.optimade'
:
'nelements = 23'
}),
headers
=
test_user_auth
)
assert
rv
.
status_code
==
200
data
=
json
.
loads
(
rv
.
data
)
assert
data
[
'pagination'
][
'total'
]
==
0
rv
=
api
.
get
(
'/repo/?%s'
%
urlencode
({
'owner'
:
'all'
,
'dft.optimade'
:
'this is not optimade'
}),
headers
=
test_user_auth
)
assert
rv
.
status_code
==
400
def
test_labels
(
self
,
api
,
non_empty_processed
,
test_user_auth
):
rv
=
api
.
get
(
'/repo/?%s'
%
urlencode
(
dict
(
owner
=
'all'
,
labels
=
[
'nonmetal'
,
'semiconductor'
]),
doseq
=
True
),
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment