Commit c3ab2505 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Preliminary fixes to optimade.

parent 70b471f0
Pipeline #76258 canceled with stages
in 4 minutes and 30 seconds
......@@ -20,5 +20,7 @@ from flask import Blueprint
from flask_restplus import Api
from .api import blueprint, url, api
from .endpoints import CalculationList, Calculation
# TODO ReferenceList, Reference, ReferenceInfo, Links are missing, because the implement
# the wrong thing.
from .endpoints import CalculationList, Calculation, CalculationInfo, Info, Structure
from .filterparser import parse_filter
......@@ -74,6 +74,10 @@ def to_calc_with_metadata(results: List[Dict[str, Any]]):
return result
# TODO the Entry/ListEntry endpoints for References, Calculations, Structures should
# reuse more code.
# Calculations are identical to structures. Not sure if this is what the optimade
# specification intends.
@ns.route('/calculations')
class CalculationList(Resource):
@api.doc('list_calculations')
......@@ -259,6 +263,9 @@ class References(Resource):
results = to_calc_with_metadata(result['results'])
assert len(results) == len(result['results']), 'Mongodb and elasticsearch are not consistent'
# TODO References are about returning user provided references to paper or web resources.
# The ReferenceObject does not have this kind of information.
# TODO Why is TopLevelLinks different from LinksModel. Any what is "TopLevel" about it.
return dict(
meta=Meta(
query=request.url,
......@@ -312,6 +319,8 @@ class Links(Resource):
page_limit=page_limit,
sort=sort, filter=filter
),
# TODO Links are about links to other optimade databases, e.g. OQMD, MP, AFLOW.
# It is not about links within NOMAD, like LinkObject suggests.
data=[LinkObject(d, page_number=page_number, sort=sort, filter=filter) for d in results]
)
......@@ -386,3 +395,29 @@ class Structure(Resource):
meta=Meta(query=request.url, returned=1),
data=StructureObject(results[0], request_fields=request_fields)
), 200
@ns.route('/info/structures')
class StructuresInfo(Resource):
@api.doc('structures_info')
@api.response(400, 'Invalid requests, e.g. bad parameter.')
@api.expect(base_endpoint_parser, validate=True)
@api.marshal_with(json_api_info_response_model, skip_none=True, code=200)
def get(self):
''' Returns information relating to the API implementation- '''
base_request_args()
result = {
'description': 'a structure entry',
'properties': {
attr.name: dict(description=attr.description)
for attr in OptimadeEntry.m_def.all_properties.values()},
'formats': ['json'],
'output_fields_by_format': {
'json': list(OptimadeEntry.m_def.all_properties.keys())}
}
return dict(
meta=Meta(query=request.url, returned=1),
data=result
), 200
......@@ -147,7 +147,7 @@ class ToplevelLinks:
self.next = url(endpoint, page_number=min((page_number + 1, last_page)), **rest)
json_api_links_model = api.model('Links', {
json_api_links_model = api.model('ApiLinks', {
'base_url': fields.String(
description='The base URL of the implementation'),
......@@ -164,7 +164,6 @@ json_api_links_model = api.model('Links', {
'first': fields.String(
description='The first page of data.')
})
......
......@@ -15,6 +15,7 @@
import json
import pytest
from nomad import config
......@@ -77,6 +78,12 @@ def test_internal_server_error_post(client, caplog):
assert data['json']['test_arg'] == 'value'
@pytest.mark.parametrize('api', ['api', 'optimade'])
def test_swagger(client, api):
rv = client.get('/%s/swagger.json' % api)
assert rv.status_code == 200
def test_docs(client):
rv = client.get('/docs/index.html')
rv = client.get('/docs/introduction.html')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment