Commit 6d453ce5 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed level of immutable_id and last_modified in structure endpoint. Fixed bad links urls.

parent d18ec8c7
Pipeline #76431 passed with stages
in 21 minutes and 18 seconds
......@@ -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
......
......@@ -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:
......
......@@ -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))
......
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