Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datamodel: test/display organizational entity #77

Merged
merged 3 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions invenio_rdm_records/marshmallow/json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
# Copyright (C) 2019 Northwestern University.
# Copyright (C) 2019-2020 CERN.
# Copyright (C) 2019-2020 Northwestern University.
#
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -51,6 +51,9 @@ class CreatorSchemaV1(BaseSchema):
"Personal"
]

# TODO: Need to revisit `name` in Deposit form:
# current mock-up doesn't have `name` field, so there is assumed
# work on the front-end to fill this value.
name = SanitizedUnicode(required=True)
type = SanitizedUnicode(required=True, validate=validate.OneOf(
choices=NAMES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

{% macro list_entities(entities) %}
{% for entity in entities %}
{%- if entity.identifiers and entity.identifiers[0] %}
{# TODO: Is the first identifier given precedence or is "Orcid" given precedence? #}
{# Assume first identifier is given precedence #}
{% set main_identifier = entity.identifiers[0] %}
{%- if main_identifier.scheme == "Orcid" %}
<a href="{{ main_identifier.identifier|pid_url('orcid') }}">
<img class="inline-orcid" src="{{ url_for('static', filename='images/orcid.svg') }}" />
</a>
{# TODO: Other potential main identifiers #}
{%- endif %}
{% else %}
{# TODO: Change for an organization icon when organizations supported #}
<i class="fa fa-user" aria-hidden="true"></i>
{# TODO: Is the first identifier given precedence or is "Orcid" given precedence? #}
{# Assume first identifier is given precedence #}
{% set main_identifier = entity.identifiers[0] if entity.identifiers and entity.identifiers[0] else {"scheme": ""} %}
{%- if main_identifier.scheme == "Orcid" %}
<a href="{{ main_identifier.identifier|pid_url('orcid') }}">
<img class="inline-orcid" src="{{ url_for('static', filename='images/orcid.svg') }}" />
</a>
{# TODO: Other potential main identifiers #}
{%- elif entity.type == "Organizational" %}
<i class="fa fa-users" aria-hidden="true"></i>
{%- else %}
<i class="fa fa-user" aria-hidden="true"></i>
{%- endif %}

<span class="text-muted" {% if entity.affiliations and entity.affiliations[0] %}data-toggle="tooltip" title="{{entity.affiliations[0].name}}"{% endif %}>{{entity.name}}</span>
{% endfor %}
{%- endmacro %}
59 changes: 28 additions & 31 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,31 @@ def full_record():
"identifier": "9999.99999",
"scheme": "arXiv"
}],
"creators": [{
"name": "Julio Cesar",
"type": "Personal",
"given_name": "Julio",
"family_name": "Cesar",
"identifiers": [{
"identifier": "9999-9999-9999-9999",
"scheme": "Orcid"
}],
"affiliations": [{
"name": "Entity One",
"identifier": "entity-one",
"scheme": "entity-id-scheme"
}]
}],
"creators": [
{
"name": "Julio Cesar",
"type": "Personal",
"given_name": "Julio",
"family_name": "Cesar",
"identifiers": [{
"identifier": "9999-9999-9999-9999",
"scheme": "Orcid"
}],
"affiliations": [{
"name": "Entity One",
"identifier": "entity-one",
"scheme": "entity-id-scheme"
}]
},
{
"name": "California Digital Library",
"type": "Organizational",
"identifiers": [{
"identifier": "03yrm5c26",
"scheme": "ROR"
}]
}
],
"titles": [{
"title": "A Romans story",
"type": "Other",
Expand Down Expand Up @@ -191,7 +201,7 @@ def full_record():
@pytest.fixture(scope='function')
def minimal_record():
"""
Dictionary with the minimum requried fields to create a record.
Dictionary with the minimum required fields to create a record.

The following attributes are injected by the de/serialization:
- recid
Expand All @@ -215,21 +225,8 @@ def minimal_record():
"identifier": "9999.99999",
"scheme": "arXiv"
}],
"creators": [{
"name": "Julio Cesar",
"type": "Personal",
"given_name": "Julio",
"family_name": "Cesar",
"identifiers": [{
"identifier": "9999-9999-9999-9999",
"scheme": "Orcid"
}],
"affiliations": [{
"name": "Entity One",
"identifier": "entity-one",
"scheme": "entity-id-scheme"
}]
}],
# Technically not required
"creators": [],
"titles": [{
"title": "A Romans story",
"type": "Other",
Expand Down
42 changes: 31 additions & 11 deletions tests/unit/test_schemas_json_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,18 @@ def test_affiliations():

def test_creator():
"""Test creator schema."""
# If present, bare minimum
valid_minimal = {
"name": "Julio Cesar",
"type": "Personal"
}

data = CreatorSchemaV1().load(valid_minimal)

assert data == valid_minimal

# Full person
valid_full_person = {
"name": "Julio Cesar",
"type": "Personal",
"given_name": "Julio",
Expand All @@ -113,16 +124,25 @@ def test_creator():
}]
}

data = CreatorSchemaV1().load(valid_minimal)
assert data == valid_minimal
data = CreatorSchemaV1().load(valid_full_person)

valid_minimal = {
"name": "Julio Cesar",
"type": "Personal"
assert data == valid_full_person

# Full organization
valid_full_org = {
"name": "California Digital Library",
"type": "Organizational",
"identifiers": [{
"identifier": "03yrm5c26",
"scheme": "ROR"
}],
# "given_name", "family_name" and "affiliations" are ignored if passed
"family_name": "I am ignored!"
}

data = CreatorSchemaV1().load(valid_minimal)
assert data == valid_minimal
data = CreatorSchemaV1().load(valid_full_org)

assert data == valid_full_org

invalid_no_name = {
"type": "Personal",
Expand All @@ -141,7 +161,7 @@ def test_creator():
with pytest.raises(ValidationError):
data = CreatorSchemaV1().load(invalid_no_name)

invalid_no_name_type = {
invalid_no_type = {
"name": "Julio Cesar",
"given_name": "Julio",
"family_name": "Cesar",
Expand All @@ -156,9 +176,9 @@ def test_creator():
}]
}
with pytest.raises(ValidationError):
data = CreatorSchemaV1().load(invalid_no_name_type)
data = CreatorSchemaV1().load(invalid_no_type)

invalid_name_type = {
invalid_type = {
"name": "Julio Cesar",
"type": "Invalid",
"given_name": "Julio",
Expand All @@ -174,7 +194,7 @@ def test_creator():
}]
}
with pytest.raises(ValidationError):
data = CreatorSchemaV1().load(invalid_name_type)
data = CreatorSchemaV1().load(invalid_type)


def test_contributor():
Expand Down