Skip to content

Commit

Permalink
Merge pull request #276 from michamos/curated-lone-references-refs
Browse files Browse the repository at this point in the history
hep: treat references with only $$0 as curated
  • Loading branch information
michamos committed Nov 25, 2020
2 parents 7b96350 + 884d0cc commit a06fa49
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion inspire_dojson/hep/rules/bd9xx.py
Expand Up @@ -260,7 +260,11 @@ def _has_curator_flag(value):
return 'CURATOR' in normalized_nine_values

def _is_curated(value):
return force_single_element(value.get('z')) == '1' and _has_curator_flag(value)
is_explicitly_curated = (
force_single_element(value.get('z')) == '1' and _has_curator_flag(value)
)
has_only_0_and_z = set(value.keys()) == {'0', 'z'}
return is_explicitly_curated or has_only_0_and_z

def _set_record(el):
recid = maybe_int(el)
Expand Down
35 changes: 35 additions & 0 deletions tests/test_hep_bd9xx.py
Expand Up @@ -1631,6 +1631,41 @@ def test_references_from_999C5_0_h_m_o_r_t_y():
assert expected == result['999C5']


def test_references_from_999C5_0_z():
schema = load_schema('hep')
subschema = schema['properties']['references']

snippet = (
'<datafield tag="999" ind1="C" ind2="5">'
' <subfield code="0">351013</subfield>'
' <subfield code="z">1</subfield>'
'</datafield>'
) # record/374213

expected = [
{
'curated_relation': True,
'record': {
'$ref': 'http://localhost:5000/api/literature/351013',
},
},
]
result = hep.do(create_record(snippet))

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

expected = [
{
'0': 351013,
'z': 1,
},
]
result = hep2marc.do(result)

assert expected == result['999C5']


def test_references_from_999C5u_as_cds_system_identifiers():
schema = load_schema('hep')
subschema = schema['properties']['references']
Expand Down

0 comments on commit a06fa49

Please sign in to comment.