Skip to content

Commit

Permalink
Merge pull request #332 from vbalbp/handle_journal_mid_letters
Browse files Browse the repository at this point in the history
utils: accept letters mid-volume in pub_info conversion
  • Loading branch information
michamos committed Oct 18, 2018
2 parents 5fbc163 + f917a9f commit 59e45f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inspire_schemas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
r'^/licenses/(?P<sublicense>[-\w]*)(?:/(?P<version>[\.\d]*))?'
)
_RE_VOLUME_STARTS_WITH_A_LETTER = re.compile(
r'^(?P<letter>[A-Z])(?P<volume>\d+)', re.IGNORECASE
r'^(?P<letter>[A-Z])(?P<volume>\d[\dA-Z]*$)', re.IGNORECASE
)
_RE_VOLUME_ENDS_WITH_A_LETTER = re.compile(
r'(?P<volume>\d+)(?P<letter>[A-Z])$', re.IGNORECASE
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def do_setup():
'pyyaml',
'rfc3987',
'six',
# requests requires a urllib3 version of 1.23, we pin it down here to solve dependency problems
'urllib3==1.23',
],
tests_require=tests_require,
extras_require=extras_require,
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,33 @@ def test_convert_old_publication_info_to_new_does_not_raise_when_deducing_year_f
assert expected == result


def test_convert_old_publication_info_to_new_handles_volumes_with_letters_in_the_middle():
schema = utils.load_schema('hep')
subschema = schema['properties']['publication_info']

publication_info = [
{
'journal_record': {
'$ref': 'http://localhost:5000/api/journals/725825',
},
'journal_title': 'Eur.Phys.J.',
'journal_volume': 'A28S1',
},
]
assert utils.validate(publication_info, subschema) is None

expected = [
{
'journal_title': 'Eur.Phys.J.A',
'journal_volume': '28S1',
},
]
result = utils.convert_old_publication_info_to_new(publication_info)

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


def test_convert_new_publication_info_to_old():
schema = utils.load_schema('hep')
subschema = schema['properties']['publication_info']
Expand Down Expand Up @@ -804,6 +831,30 @@ def test_convert_new_publication_info_to_old_handles_year_added_to_volumes():
assert expected == result


def test_convert_new_publication_info_to_old_handles_volumes_with_letters_in_the_middle():
schema = utils.load_schema('hep')
subschema = schema['properties']['publication_info']

publication_info = [
{
'journal_title': 'Eur.Phys.J.A',
'journal_volume': '28S1',
},
]
assert utils.validate(publication_info, subschema) is None

expected = [
{
'journal_title': 'Eur.Phys.J.',
'journal_volume': 'A28S1',
},
]
result = utils.convert_new_publication_info_to_old(publication_info)

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


def test_draft_validate():
schema = utils.load_schema('hep')

Expand Down

0 comments on commit 59e45f0

Please sign in to comment.