Skip to content

Commit

Permalink
Merge pull request #358 from ammirate/builder_add_name_variant
Browse files Browse the repository at this point in the history
builder: add `add_name_variant` to author builder
  • Loading branch information
ammirate committed Apr 8, 2019
2 parents 497048f + a74d0da commit 34bc124
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions inspire_schemas/builders/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def set_display_name(self, name):
self._ensure_field('name', {})
self.obj['name']['preferred_name'] = name

@filter_empty_parameters
def add_name_variant(self, name):
"""Add name variant.
Args:
:param name: name variant for the current author.
:type name: string
"""
self._ensure_field('name', {})
self.obj['name'].setdefault('name_variants', []).append(name)

@filter_empty_parameters
def add_native_name(self, name):
"""Add native name.
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_author_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ def test_set_display_name_can_be_called_multiple_times():
assert expected == result


def test_add_name_variant():
schema = load_schema('authors')
subschema = schema['properties']['name']

author = AuthorBuilder()
author.set_name('Abad, Francisco Jose Garcia')
author.add_native_name('Garcia Abad')
author.add_native_name('Francisco Jose')
# record 1653906

expected = {
'value': 'Abad, Francisco Jose Garcia',
'native_names': [
'Garcia Abad',
'Francisco Jose'
]
}
result = author.obj['name']

assert validate(result, subschema) is None
assert expected == result


def test_add_native_name():
schema = load_schema('authors')
subschema = schema['properties']['name']
Expand Down

0 comments on commit 34bc124

Please sign in to comment.