Skip to content

Commit

Permalink
data: migrate dois field
Browse files Browse the repository at this point in the history
Signed-off-by: Micha Moskovic <[email protected]>
  • Loading branch information
michamos authored and jacquerie committed Mar 5, 2018
1 parent 2a9c427 commit 886c228
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions inspire_dojson/data/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@

from __future__ import absolute_import, division, print_function

from dojson import utils
from idutils import normalize_doi

from .model import data
from ..utils import force_single_element, get_record_ref


@data.over('dois', '^0247.')
@utils.for_each_value
def dois(self, key, value):
return {
'source': value.get('9'),
'value': normalize_doi(value.get('a')),
}


@data.over('new_record', '^970..')
def new_record(self, key, value):
new_recid = force_single_element(value.get('d'))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'Flask~=0.0,>=0.12.2',
'IDUtils~=0.0,>=0.2.4',
'dojson~=1.0,>=1.3.1',
'inspire-schemas~=57.0,>=57.0.0',
'inspire-schemas~=57.0,>=57.1.0',
'inspire-utils~=2.0,>=2.0.0',
'isbnid_fork~=0.0,>=0.5.2',
'langdetect~=1.0,>=1.0.7',
Expand Down
22 changes: 22 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@
from inspire_schemas.api import load_schema, validate


def test_dois_from_0247_2_a():
schema = load_schema('data')
subschema = schema['properties']['dois']

snippet = (
'<datafield tag="024" ind1="7" ind2=" ">'
' <subfield code="a">10.17182/hepdata.77268.v1/t6</subfield>'
' <subfield code="2">DOI</subfield>'
'</datafield>'
) # record/1639676

expected = [
{
'value': '10.17182/hepdata.77268.v1/t6',
}
]
result = data.do(create_record(snippet))

assert validate(result['dois'], subschema) is None
assert expected == result['dois']


def test_new_record_from_970__d():
schema = load_schema('data')
subschema = schema['properties']['new_record']
Expand Down

0 comments on commit 886c228

Please sign in to comment.