Skip to content

Commit

Permalink
Merge 0dda8c4 into 2806583
Browse files Browse the repository at this point in the history
  • Loading branch information
harunurhan committed Nov 13, 2018
2 parents 2806583 + 0dda8c4 commit ed78f35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions inspire_schemas/builders/authors.py
Expand Up @@ -28,6 +28,7 @@
from inspire_utils.date import normalize_date, PartialDate
from inspire_utils.helpers import force_list
from inspire_utils.name import normalize_name
from inspire_utils.record import get_value

from ..utils import EMPTIES, filter_empty_parameters, load_schema

Expand Down Expand Up @@ -114,9 +115,11 @@ def add_email_address(self, email):
:param email: public email of the author.
:type email: string
"""
self._append_to('email_addresses', {
"value": email
})
emails = get_value(self.obj, 'email_addresses.value')
if emails is None or email not in emails:
self._append_to('email_addresses', {
"value": email
})

@filter_empty_parameters
def set_status(self, status):
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_author_builder.py
Expand Up @@ -202,6 +202,23 @@ def test_add_multiple_email_addresses():
assert expected == result


def test_add_email_addresses_skips_duplicate_ones():
schema = load_schema('authors')
subschema = schema['properties']['email_addresses']

author = AuthorBuilder()
author.add_email_address('example@test.com')
author.add_email_address('example@test.com')

expected = [{
"value": 'example@test.com'
}]
result = author.obj['email_addresses']

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


def test_set_status():
schema = load_schema('authors')
subschema = schema['properties']['status']
Expand Down

0 comments on commit ed78f35

Please sign in to comment.