diff --git a/nomad/app/optimade/endpoints.py b/nomad/app/optimade/endpoints.py index 14258fab96a1cd2840407725c3b4d85683a40a56..b3dede57ef55821ee9bd78784a4aa157a828235e 100644 --- a/nomad/app/optimade/endpoints.py +++ b/nomad/app/optimade/endpoints.py @@ -80,7 +80,7 @@ class CalculationList(Resource): filter = request.args.get('filter', None) page_limit = int(request.args.get('page_limit', 10)) page_number = int(request.args.get('page_number', 1)) - sort = request.args.get('sort', 'chemical_formula_reduced'), + sort = request.args.get('sort', 'chemical_formula_reduced') except Exception: abort(400, message='bad parameter types') # TODO Specific json API error handling diff --git a/nomad/app/optimade/models.py b/nomad/app/optimade/models.py index 152d2aa556a030e4ce3a49f829f4b2d34ec3f3a7..eefca99b471013ff257d1df5b52ecfe95cd69e86 100644 --- a/nomad/app/optimade/models.py +++ b/nomad/app/optimade/models.py @@ -213,16 +213,10 @@ json_api_data_object_model = api.model('DataObject', { 'id': fields.String( description='The id of the object.'), - 'immutable_id': fields.String( - description='The entries immutable id.'), - - 'last_modified': RFC3339DateTime( - description='Date and time representing when the entry was last modified.'), - 'attributes': fields.Raw( description='A dictionary, containing key-value pairs representing the entries properties') - # TODO + # TODO # further optional fields: links, meta, relationships }) @@ -281,11 +275,11 @@ class CalculationDataObject: return False attrs = {key: value for key, value in calc.dft.optimade.m_to_dict().items() if include(key)} + attrs['immutable_id'] = calc.calc_id + attrs['last_modified'] = calc.last_processing if calc.last_processing is not None else calc.upload_time self.type = 'calculation' self.id = calc.calc_id - self.immutable_id = calc.calc_id - self.last_modified = calc.last_processing if calc.last_processing is not None else calc.upload_time self.attributes = attrs @@ -294,14 +288,12 @@ class StructureObject: optimade_quantities = calc.dft.optimade.m_to_dict() attrs = {key: val for key, val in optimade_quantities.items() if request_fields is None or key in request_fields} + attrs['immutable_id'] = calc.calc_id attrs['last_modified'] = calc.last_processing if calc.last_processing is not None else calc.upload_time self.type = 'structure' self.id = calc.calc_id - self.links = None - self.meta = None self.attributes = attrs - self.relationships = None class ReferenceObject: @@ -313,10 +305,7 @@ class ReferenceObject: self.type = 'calculation' self.id = calc.calc_id - self.links = None - self.meta = None self.attributes = attrs - self.relationships = None class LinkObject: @@ -329,10 +318,7 @@ class LinkObject: ) self.type = 'child' self.id = calc.calc_id - self.links = None - self.meta = None self.attributes = attrs - self.relationships = None class Property: diff --git a/tests/app/test_optimade.py b/tests/app/test_optimade.py index f7faa1aade3d914853099e94fde6b9ce1579ad49..9bdb0284fcd668c38ee1071c983c04921843afd4 100644 --- a/tests/app/test_optimade.py +++ b/tests/app/test_optimade.py @@ -180,9 +180,8 @@ def test_list_endpoint_request_fields(api, example_structures): ref_elements = [['H', 'O'], ['C', 'H', 'O'], ['H', 'O'], ['H', 'O']] data['data'] = sorted(data['data'], key=lambda x: x['id']) for i in range(len(data['data'])): - rf = list(data['data'][i]['attributes'].keys()) - rf.sort() - assert rf == ['elements', 'nelements'] + rf = sorted(list(data['data'][i]['attributes'].keys())) + assert rf == ['elements', 'immutable_id', 'last_modified', 'nelements'] assert_eq_attrib(data, 'elements', ref_elements[i], i) assert_eq_attrib(data, 'nelements', len(ref_elements[i]), i) @@ -192,8 +191,8 @@ def test_single_endpoint_request_fields(api, example_structures): assert rv.status_code == 200 data = json.loads(rv.data) ref_elements = ['H', 'O'] - rf = list(data['data']['attributes'].keys()) - assert rf == ['elements', 'nelements'] + rf = sorted(list(data['data']['attributes'].keys())) + assert rf == ['elements', 'immutable_id', 'last_modified', 'nelements'] assert_eq_attrib(data, 'elements', ref_elements) assert_eq_attrib(data, 'nelements', len(ref_elements))