Skip to content

Commit

Permalink
datamodel: add alternative descriptions field
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Panero committed Oct 25, 2019
1 parent c9df086 commit a6a16e7
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
33 changes: 33 additions & 0 deletions invenio_rdm_records/jsonschemas/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
"TranslatedTitle",
"Other"
]
},
"description_type": {
"type": "string",
"enum": [
"Abstract",
"Methods",
"SeriesInformation",
"TableOfContents",
"TechnicalInfo",
"Other"
]
}
},
"type": "object",
Expand Down Expand Up @@ -44,6 +55,28 @@
],
"type": "string"
},
"additional_descriptions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"description": {
"description": "Description/abstract for record.",
"type": "string"
},
"description_type": {
"description": "Type of description.",
"$ref": "#/definitions/description_type"
},
"lang": {
"description": "Language of the description.",
"type": "string"
}
},
"required": ["description", "description_type"]
},
"uniqueItems": true
},
"additional_titles": {
"type": "array",
"items": {
Expand Down
14 changes: 14 additions & 0 deletions invenio_rdm_records/mappings/v6/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
"access_right": {
"type": "keyword"
},
"additional_descriptions": {
"type": "object",
"properties": {
"description": {
"type": "text"
},
"description_type": {
"type": "keyword"
},
"lang": {
"type": "keyword"
}
}
},
"additional_titles": {
"type": "object",
"properties": {
Expand Down
14 changes: 14 additions & 0 deletions invenio_rdm_records/mappings/v7/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
"access_right": {
"type": "keyword"
},
"additional_descriptions": {
"type": "object",
"properties": {
"description": {
"type": "text"
},
"description_type": {
"type": "keyword"
},
"lang": {
"type": "keyword"
}
}
},
"additional_titles": {
"type": "object",
"properties": {
Expand Down
11 changes: 11 additions & 0 deletions invenio_rdm_records/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,23 @@ class TitleSchemaV1(StrictKeysMixin):
lang = SanitizedUnicode()


class DescriptionSchemaV1(StrictKeysMixin):
"""Schema for the additional descriptions."""

description = SanitizedUnicode(required=True,
validate=validate.Length(min=3))
# TODO: Shall it be checked against the enum?
description_type = SanitizedUnicode()
lang = SanitizedUnicode()


class MetadataSchemaV1(StrictKeysMixin):
"""Schema for the record metadata."""

# TODO: Check enumeration (i.e. only open/embargoed/... accepted)
access_right = SanitizedUnicode(required=True)
access = fields.Nested(AccessSchemaV1)
additional_descriptions = fields.List(fields.Nested(DescriptionSchemaV1))
additional_titles = fields.List(fields.Nested(TitleSchemaV1))
recid = PersistentIdentifier()
title = SanitizedUnicode(required=True, validate=validate.Length(min=3))
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_schemas_json_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ def test_invalid_additional_titles(val):
assert 'additional_titles' in errors


@pytest.mark.parametrize(('val', 'expected'), [
([dict(description='Full additional description',
description_type='Description type',
lang='en')], None),
([dict(description='Only required fields',
description_type='Description type')], None),
])
def test_valid_additional_descriptions(val, expected):
"""Test additional descriptions."""
data, errors = MetadataSchemaV1(partial=['additional_descriptions']).load(
dict(additional_descriptions=val))

if expected is not None:
assert data['additional_descriptions'] == expected
else:
assert data['additional_descriptions'] == val


@pytest.mark.parametrize('val', [
([dict(description_type='Invalid no description', lang='en')], None),
([dict(description='Invalid no description type', lang='en')], None),
([dict(lang='en')], None),
])
def test_invalid_additional_descriptions(val):
"""Test additional descriptions."""
data, errors = MetadataSchemaV1(partial=['additional_descriptions']).load(
dict(additional_descriptions=val))
assert 'additional_descriptions' in errors


@pytest.mark.parametrize(('val', 'expected'), [
('2016-01-02', '2016-01-02'),
(' 2016-01-02 ', '2016-01-02'),
Expand Down

0 comments on commit a6a16e7

Please sign in to comment.