diff --git a/sonar/modules/documents/marshmallow/json.py b/sonar/modules/documents/marshmallow/json.py index 0313ce4e..f7001de1 100644 --- a/sonar/modules/documents/marshmallow/json.py +++ b/sonar/modules/documents/marshmallow/json.py @@ -47,9 +47,18 @@ class ThumbnailSchemaV1(StrictKeysMixin): class Meta: """Meta for file schema.""" + unknown = EXCLUDE + + key = SanitizedUnicode() + label = SanitizedUnicode() + type = SanitizedUnicode() + order = fields.Integer() + restriction = fields.Dict(dump_only=True) + links = fields.Dict(dump_only=True) thumbnail = SanitizedUnicode(dump_only=True) + class FileSchemaV1(ThumbnailSchemaV1): """File schema.""" @@ -64,20 +73,13 @@ class Meta: bucket = SanitizedUnicode() file_id = SanitizedUnicode() version_id = SanitizedUnicode() - key = SanitizedUnicode() mimetype = SanitizedUnicode() checksum = SanitizedUnicode() size = fields.Integer() - label = SanitizedUnicode() - type = SanitizedUnicode() - order = fields.Integer() external_url = SanitizedUnicode() access = SanitizedUnicode() restricted_outside_organisation = fields.Boolean() embargo_date = SanitizedUnicode() - restriction = fields.Dict(dump_only=True) - links = fields.Dict(dump_only=True) - thumbnail = SanitizedUnicode(dump_only=True) permissions = fields.Dict(dump_only=True) @pre_dump diff --git a/tests/api/documents/test_documents_rest.py b/tests/api/documents/test_documents_rest.py index d690663a..af673233 100644 --- a/tests/api/documents/test_documents_rest.py +++ b/tests/api/documents/test_documents_rest.py @@ -29,7 +29,11 @@ def test_get(client, document_with_file): assert res.status_code == 200 assert res.json['hits']['total']['value'] == 1 # the search results does not contains permissions - assert not res.json['hits']['hits'][0]['metadata']['_files'][0].get("permissions") + fdata = res.json['hits']['hits'][0]['metadata']['_files'][0] + assert list(fdata.keys()) == [ + 'key', 'label', 'type', 'order', 'restriction', 'links', 'thumbnail' + ] + assert not fdata.get("permissions") # the item result should contains permissions res = client.get(url_for('invenio_records_rest.doc_item', pid_value=document_with_file['pid']))