Example #1
0
def test_ids_from_035__9():
    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">INSPIRE</subfield>'
        '  </datafield>'  # record/edit/?ln=en#state=edit&recid=1474355&recrev=20160707223728
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '  </datafield>'  # record/1364570/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">KAKEN</subfield>'
        '  </datafield>'  # record/1480252/export/xme
        '</record>')

    result = hepnames.do(create_record(snippet))

    assert 'ids' not in result
Example #2
0
def test_ids_from_double_035__a_9_with_kaken():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">BAI</subfield>'
        '    <subfield code="a">Toshio.Suzuki.2</subfield>'
        '  </datafield>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">KAKEN</subfield>'
        '    <subfield code="a">70139070</subfield>'
        '  </datafield>'
        '</record>'
    )  # record/1474271/export/xme

    expected = [
        {
            'schema': 'INSPIRE BAI',
            'value': 'Toshio.Suzuki.2',
        },
        {
            'schema': 'KAKEN',
            'value': 'KAKEN-70139070',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            '9': 'BAI',
            'a': 'Toshio.Suzuki.2',
        },
        {
            '9': 'KAKEN',
            'a': 'KAKEN-70139070',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Example #3
0
def test_advisors_from_701__a_g_i():
    schema = load_schema('authors')
    subschema = schema['properties']['advisors']

    snippet = (
        '<datafield tag="701" ind1=" " ind2=" ">'
        '  <subfield code="a">Rivelles, Victor O.</subfield>'
        '  <subfield code="g">PhD</subfield>'
        '  <subfield code="i">INSPIRE-00120420</subfield>'
        '  <subfield code="x">991627</subfield>'
        '  <subfield code="y">1</subfield>'
        '</datafield>'
    )  # record/1474091/export/xme

    expected = [
        {
            'name': 'Rivelles, Victor O.',
            'degree_type': 'PhD',
            'ids': [
                {
                    'schema': 'INSPIRE ID',
                    'value': 'INSPIRE-00120420'
                }
            ],
            'record': {
                '$ref': 'http://localhost:5000/api/authors/991627',
            },
            'curated_relation': True
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'a': 'Rivelles, Victor O.',
            'g': 'PhD',
            'i': 'INSPIRE-00120420',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['701']
def test_new_record_from_970__d():
    schema = load_schema('authors')
    subschema = schema['properties']['new_record']

    snippet = ('<datafield tag="970" ind1=" " ind2=" ">'
               '  <subfield code="d">1039458</subfield>'
               '</datafield>')  # record/1271254

    expected = {'$ref': 'http://localhost:5000/api/authors/1039458'}
    result = hepnames.do(create_record(snippet))

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

    expected = {'d': 1039458}
    result = hepnames2marc.do(result)

    assert expected == result['970']
Example #5
0
def test_positions_from_371__a_r_t_z():
    schema = load_schema('authors')
    subschema = schema['properties']['positions']

    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">San Luis Potosi U.</subfield>'
        '  <subfield code="r">Master</subfield>'
        '  <subfield code="t">2007</subfield>'
        '  <subfield code="z">903830</subfield>'
        '</datafield>'
    )  # record/1037568

    expected = [
        {
            '_rank': 'Master',
            'current': False,
            'end_date': '2007',
            'institution': {
                'curated_relation': True,
                'name': 'San Luis Potosi U.',
                'record': {
                    '$ref': 'http://localhost:5000/api/institutions/903830',
                },
            },
            'rank': 'MASTER',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'a': 'San Luis Potosi U.',
            'r': 'MAS',
            't': '2007',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['371']
Example #6
0
def test_ids_from_double_035__a_9():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = ('<record>'
               '  <datafield tag="035" ind1=" " ind2=" ">'
               '    <subfield code="a">INSPIRE-00134135</subfield>'
               '    <subfield code="9">INSPIRE</subfield>'
               '  </datafield>'
               '  <datafield tag="035" ind1=" " ind2=" ">'
               '    <subfield code="a">H.Vogel.1</subfield>'
               '    <subfield code="9">BAI</subfield>'
               '  </datafield>'
               '</record>')  # record/984519

    expected = [
        {
            'schema': 'INSPIRE ID',
            'value': 'INSPIRE-00134135',
        },
        {
            'schema': 'INSPIRE BAI',
            'value': 'H.Vogel.1',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [{
        'a': 'INSPIRE-00134135',
        '9': 'INSPIRE'
    }, {
        'a': 'H.Vogel.1',
        '9': 'BAI'
    }]
    result = hepnames2marc.do(result)

    for el in expected:
        assert el in result['035']
    for el in result['035']:
        assert el in expected
Example #7
0
def test_positions_from_371__a_m_r_z():
    schema = load_schema('authors')
    subschema = schema['properties']['positions']

    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">Antwerp U.</subfield>'
        '  <subfield code="m">[email protected]</subfield>'
        '  <subfield code="r">SENIOR</subfield>'
        '  <subfield code="z">Current</subfield>'
        '</datafield>'
    )  # record/997958

    expected = [
        {
            'current': True,
            'emails': [
                '*****@*****.**',
            ],
            'institution': {
                'curated_relation': False,
                'name': 'Antwerp U.',
            },
            'rank': 'SENIOR',
            '_rank': 'SENIOR',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'a': 'Antwerp U.',
            'm': ['*****@*****.**'],
            'r': 'SENIOR',
            'z': 'Current'
        }
    ]
    result = hepnames2marc.do(result)

    assert expected == result['371']
def test_legacy_creation_date_from_961__double_x_does_not_raise():
    schema = load_schema('authors')
    subschema = schema['properties']['legacy_creation_date']

    snippet = ('<datafield tag="961" ind1=" " ind2=" ">'
               '  <subfield code="x">2006-04-21</subfield>'
               '  <subfield code="x">1996-09-01</subfield>'
               '</datafield>')  # record/982164

    expected = '1996-09-01'
    result = hepnames.do(create_record(snippet))

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

    expected = {'x': '1996-09-01'}
    result = hepnames2marc.do(result)

    assert expected == result['961']
Example #9
0
def test_positions_from_371__a_double_m_z():
    schema = load_schema('authors')
    subschema = schema['properties']['positions']

    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">Argonne</subfield>'
        '  <subfield code="m">[email protected]</subfield>'
        '  <subfield code="m">[email protected]</subfield>'
        '  <subfield code="z">current</subfield>'
        '</datafield>'
    )  # record/1408378

    expected = [
        {
            'current': True,
            'emails': [
                '*****@*****.**',
                '*****@*****.**',
            ],
            'institution': {
                'curated_relation': False,
                'name': 'Argonne',
            },
        }
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'a': 'Argonne',
            'm': ['*****@*****.**', '*****@*****.**'],
            'z': 'Current'
        }
    ]

    result = hepnames2marc.do(result)

    assert expected == result['371']
def test_urls_from_8564_u_and_8564_g_u_y():
    schema = load_schema('authors')
    subschema = schema['properties']['urls']

    snippet = (
        '<record>'
        '  <datafield tag="856" ind1="4" ind2=" ">'
        '    <subfield code="u">http://www.haydenplanetarium.org/tyson/</subfield>'
        '  </datafield>'
        '  <datafield tag="856" ind1="4" ind2=" ">'
        '    <subfield code="g">active</subfield>'
        '    <subfield code="u">https://twitter.com/neiltyson</subfield>'
        '    <subfield code="y">TWITTER</subfield>'
        '  </datafield>'
        '</record>')  # record/1073331

    expected = [
        {
            'value': 'http://www.haydenplanetarium.org/tyson/'
        },
        {
            'description': 'TWITTER',
            'value': 'https://twitter.com/neiltyson',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'u': 'http://www.haydenplanetarium.org/tyson/'
        },
        {
            'u': 'https://twitter.com/neiltyson',
            'y': 'TWITTER',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['8564']
Example #11
0
def test_stub_from_980__a_not_useful():
    schema = load_schema('authors')
    subschema = schema['properties']['stub']

    snippet = (
        '<datafield tag="980" ind1=" " ind2=" ">'
        '  <subfield code="a">HEPNAMES</subfield>'
        '</datafield>'
    )  # record/1019103

    expected = True
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {'a': 'HEPNAMES'},
    ]
    result = hepnames2marc.do(result)

    assert expected == result['980']
Example #12
0
def test_positions_from_371__a_r_t():
    schema = load_schema('authors')
    subschema = schema['properties']['positions']

    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">Case Western Reserve U.</subfield>'
        '  <subfield code="r">UNDERGRADUATE</subfield>'
        '  <subfield code="t">2011</subfield>'
        '</datafield>'
    )  # record/1590188

    expected = [
        {
            '_rank': 'UNDERGRADUATE',
            'current': False,
            'end_date': '2011',
            'institution': {
                'curated_relation': False,
                'name': 'Case Western Reserve U.',
            },
            'rank': 'UNDERGRADUATE',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'a': 'Case Western Reserve U.',
            'r': 'UG',
            't': '2011',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['371']
def test_old_single_email_from_371__a():
    schema = load_schema('authors')
    subschema = schema['properties']['positions']

    snippet = ('<datafield tag="371" ind1=" " ind2=" ">'
               '   <subfield code="a">IMSc, Chennai</subfield>'
               '   <subfield code="o">[email protected]</subfield>'
               '   <subfield code="r">PD</subfield>'
               '   <subfield code="s">2012</subfield>'
               '   <subfield code="t">2013</subfield>'
               '</datafield>')  # record/1060782

    expected = [{
        "current": False,
        "old_emails": ["*****@*****.**"],
        "end_date": "2013",
        "rank": "POSTDOC",
        "institution": {
            "name": "IMSc, Chennai",
            "curated_relation": False
        },
        "_rank": "PD",
        "start_date": "2012"
    }]
    result = hepnames.do(create_record(snippet))

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

    expected = [{
        "a": "IMSc, Chennai",
        "o": ["*****@*****.**"],
        "s": "2012",
        "r": "PD",
        "t": "2013"
    }]
    result = hepnames2marc.do(result)

    assert expected == result['371']
def test_public_notes_from_667__a():
    schema = load_schema('authors')
    subschema = schema['properties']['public_notes']

    snippet = (
        '<datafield tag="667" ind1=" " ind2=" ">'
        '  <subfield code="a">Do not confuse with Acharya, Bannanje Sripath</subfield>'
        '</datafield>')  # record/1018999

    expected = [{'value': 'Do not confuse with Acharya, Bannanje Sripath'}]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            'a': 'Do not confuse with Acharya, Bannanje Sripath'
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['667']
def test_ids_from_035__a_9_with_cern():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">CERN</subfield>'
               '  <subfield code="a">CERN-622961</subfield>'
               '</datafield>')  # record/1064570/export/xme

    expected = [
        {
            'schema': 'CERN',
            'value': 'CERN-622961',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [{'9': 'CERN', 'a': 'CERN-622961'}]
    result = hepnames2marc.do(result)

    assert expected == result['035']
def test_status_from_100__a_g_q():
    schema = load_schema('authors')
    subschema = schema['properties']['status']

    snippet = ('<datafield tag="100" ind1=" " ind2=" ">'
               '  <subfield code="a">Abarbanel, Henry D.I.</subfield>'
               '  <subfield code="q">Henry D.I. Abarbanel</subfield>'
               '  <subfield code="g">ACTIVE</subfield>'
               '</datafield>')  # record/1019100

    expected = 'active'
    result = hepnames.do(create_record(snippet))

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

    expected = {
        'a': 'Abarbanel, Henry D.I.',
        'q': 'Henry D.I. Abarbanel',
        'g': 'active',
    }
    result = hepnames2marc.do(result)

    assert expected == result['100']
Example #17
0
def test_private_notes_from_595__9():
    snippet = ('<datafield tag="595" ind1=" " ind2=" ">'
               '  <subfield code="9">SPIRES-HIDDEN</subfield>'
               '</datafield>')  # record/1005469

    assert '_private_notes' not in hepnames.do(create_record(snippet))
Example #18
0
def test_ids_from_035__a_9_with_cern_malformed():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CERN-CERN-645257</subfield>'
        '  </datafield>'  # record/1030771/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">cern-783683</subfield>'
        '  </datafield>'  # record/1408145/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CERM-724319</subfield>'
        '  </datafield>'  # record/1244430/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CNER-727986</subfield>'
        '  </datafield>'  # record/1068077/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CVERN-765559</subfield>'
        '  </datafield>'  # record/1340631/export/xme
        '</record>'
    )

    expected = [
        {
            'schema': 'CERN',
            'value': 'CERN-645257',
        },
        {
            'schema': 'CERN',
            'value': 'CERN-783683',
        },
        {
            'schema': 'CERN',
            'value': 'CERN-724319',
        },
        {
            'schema': 'CERN',
            'value': 'CERN-727986',
        },
        {
            'schema': 'CERN',
            'value': 'CERN-765559',
        },
    ]
    result = hepnames.do(create_record(snippet))

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

    expected = [
        {
            '9': 'CERN',
            'a': 'CERN-645257',
        },
        {
            '9': 'CERN',
            'a': 'CERN-783683',
        },
        {
            '9': 'CERN',
            'a': 'CERN-724319',
        },
        {
            '9': 'CERN',
            'a': 'CERN-727986',
        },
        {
            '9': 'CERN',
            'a': 'CERN-765559',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']