Esempio n. 1
0
def test_record2marcxml_handles_repeated_subfields():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'authors': [
            {
                'affiliations': [
                    {'value': 'SISSA, Trieste'},
                    {'value': 'Meudon Observ.'},
                ],
                'full_name': 'Puy, Denis',
            },
        ],
    }

    expected = (
        b'<record>\n'
        b'  <datafield tag="100" ind1=" " ind2=" ">\n'
        b'    <subfield code="a">Puy, Denis</subfield>\n'
        b'    <subfield code="u">SISSA, Trieste</subfield>\n'
        b'    <subfield code="u">Meudon Observ.</subfield>\n'
        b'  </datafield>\n'
        b'</record>\n'
    )
    result = record2marcxml(record)

    assert expected == result
Esempio n. 2
0
def test_oai_get_single_identifier_for_arxiv_set(inspire_app,
                                                 celery_app_with_context,
                                                 celery_session_worker):
    data = {
        "arxiv_eprints": [{
            "value": "2009.01484"
        }],
        "report_numbers": [{
            "value": "CERN-TH-2020-136"
        }],
    }

    record_data = faker.record("lit", data)
    record = LiteratureRecord.create(record_data)
    record_marcxml = record2marcxml(record)
    db.session.commit()

    set_name = inspire_app.config["OAI_SET_CERN_ARXIV"]
    oaiset = OAISet(spec=f"{set_name}", name="Test", description="Test")
    db.session.add(oaiset)
    db.session.commit()

    sleep(2)

    with inspire_app.test_client() as client:
        response = client.get(
            f"/api/oai2d?verb=GetRecord&metadataPrefix=marcxml&identifier=oai:inspirehep.net:{record['control_number']}"
        )
        assert record_marcxml in response.data
Esempio n. 3
0
def test_oai_get_single_identifier_for_CDS_set(inspire_app, clean_celery_session):
    data = {"_export_to": {"CDS": True}}
    record_data = faker.record("lit", data)
    record = LiteratureRecord.create(record_data)
    record_uuid = record.id
    record_marcxml = record2marcxml(record)
    db.session.commit()

    def assert_the_record_is_indexed():
        current_search.flush_and_refresh("*")
        result = es_search("records-hep")
        uuids = get_value(result, "hits.hits._id")
        assert str(record_uuid) in uuids

    retry_until_pass(assert_the_record_is_indexed)

    set_name = inspire_app.config["OAI_SET_CDS"]
    oaiset = OAISet(spec=f"{set_name}", name="Test", description="Test")
    db.session.add(oaiset)
    db.session.commit()

    with inspire_app.test_client() as client:
        response = client.get(
            f"/api/oai2d?verb=GetRecord&metadataPrefix=marcxml&identifier=oai:inspirehep.net:{record['control_number']}"
        )
        assert record_marcxml in response.data
Esempio n. 4
0
def test_oai_with_for_arxiv_set(inspire_app, clean_celery_session):
    data = {
        "arxiv_eprints": [{"value": "2009.01484"}],
        "report_numbers": [{"value": "CERN-TH-2020-136"}],
    }

    record_data = faker.record("lit", data)
    record = LiteratureRecord.create(record_data)
    record_uuid = record.id
    record_marcxml = record2marcxml(record)
    db.session.commit()

    def assert_the_record_is_indexed():
        current_search.flush_and_refresh("*")
        result = es_search("records-hep")
        uuids = get_value(result, "hits.hits._id")
        assert str(record_uuid) in uuids

    retry_until_pass(assert_the_record_is_indexed)

    set_name = inspire_app.config["OAI_SET_CERN_ARXIV"]
    oaiset = OAISet(spec=f"{set_name}", name="Test", description="Test")
    db.session.add(oaiset)
    db.session.commit()
    with inspire_app.test_client() as client:
        response = client.get(
            f"/api/oai2d?verb=ListRecords&metadataPrefix=marcxml&set={set_name}"
        )
        assert record_marcxml in response.data
Esempio n. 5
0
def test_record2marcxml_supports_relative_urls():
    record = {
        '$schema': '/schemas/records/hep.json',
        'control_number': 4328,
    }

    expected = (b'<record>\n'
                b'  <controlfield tag="001">4328</controlfield>\n'
                b'</record>\n')
    result = record2marcxml(record)

    assert expected == result
Esempio n. 6
0
def test_record2marcxml_supports_authors():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/authors.json',
        'control_number': 1010819,
    }

    expected = (b'<record>\n'
                b'  <controlfield tag="001">1010819</controlfield>\n'
                b'</record>\n')
    result = record2marcxml(record)

    assert expected == result
Esempio n. 7
0
def test_record2marcxml_generates_controlfields():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'control_number': 4328,
    }

    expected = (b'<record>\n'
                b'  <controlfield tag="001">4328</controlfield>\n'
                b'</record>\n')
    result = record2marcxml(record)

    assert expected == result
Esempio n. 8
0
def test_record2marcxml_handles_numbers():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'publication_info': [
            {'year': 1975},
        ],
    }

    expected = (
        b'<record>\n'
        b'  <datafield tag="773" ind1=" " ind2=" ">\n'
        b'    <subfield code="y">1975</subfield>\n'
        b'  </datafield>\n'
        b'</record>\n'
    )
    result = record2marcxml(record)

    assert expected == result
Esempio n. 9
0
def test_record2marcxml_handles_unicode():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'authors': [
            {'full_name': u'Kätlne, J.'},
        ],
    }

    expected = (
        b'<record>\n'
        b'  <datafield tag="100" ind1=" " ind2=" ">\n'
        b'    <subfield code="a">K\xc3\xa4tlne, J.</subfield>\n'
        b'  </datafield>\n'
        b'</record>\n'
    )
    result = record2marcxml(record)

    assert expected == result
Esempio n. 10
0
def test_record2marcxml_generates_datafields():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'authors': [
            {'full_name': 'Glashow, S.L.'},
        ],
    }

    expected = (
        b'<record>\n'
        b'  <datafield tag="100" ind1=" " ind2=" ">\n'
        b'    <subfield code="a">Glashow, S.L.</subfield>\n'
        b'  </datafield>\n'
        b'</record>\n'
    )
    result = record2marcxml(record)

    assert expected == result
Esempio n. 11
0
def test_record2marcxml_generates_indices():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'inspire_categories': [
            {'term': 'Accelerators'},
        ],
    }

    expected = (
        b'<record>\n'
        b'  <datafield tag="650" ind1="1" ind2="7">\n'
        b'    <subfield code="2">INSPIRE</subfield>\n'
        b'    <subfield code="a">Accelerators</subfield>\n'
        b'  </datafield>\n'
        b'</record>\n'
    )
    result = record2marcxml(record)

    assert expected == result
Esempio n. 12
0
def test_record2marcxml_handles_repeated_fields():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        '_collections': [
            'Literature',
            'HAL Hidden',
        ],
    }

    expected = (b'<record>\n'
                b'  <datafield tag="980" ind1=" " ind2=" ">\n'
                b'    <subfield code="a">HEP</subfield>\n'
                b'  </datafield>\n'
                b'  <datafield tag="980" ind1=" " ind2=" ">\n'
                b'    <subfield code="a">HALhidden</subfield>\n'
                b'  </datafield>\n'
                b'</record>\n')
    result = record2marcxml(record)

    assert expected == result
Esempio n. 13
0
def test_oai_with_for_cds_set(inspire_app, celery_app_with_context,
                              celery_session_worker):
    data = {"_export_to": {"CDS": True}}
    record_data = faker.record("lit", data)
    record = LiteratureRecord.create(record_data)
    record_marcxml = record2marcxml(record)
    db.session.commit()

    set_name = inspire_app.config["OAI_SET_CDS"]
    oaiset = OAISet(spec=f"{set_name}", name="Test", description="Test")
    db.session.add(oaiset)
    db.session.commit()

    sleep(2)

    with inspire_app.test_client() as client:
        response = client.get(
            f"/api/oai2d?verb=ListRecords&metadataPrefix=marcxml&set={set_name}"
        )
        assert record_marcxml in response.data
Esempio n. 14
0
def test_record2marcxml_strips_control_characters():
    record = {
        '$schema': 'http://localhost:5000/schemas/records/hep.json',
        'abstracts': [
            {
                'source': 'submitter',
                'value': u'A common feature shared by many quantum gravity models is modi\u001Ccations of two-point functions at energy scales around the Planck scale.',
            },
        ],
    }  # holdingpen/812647

    expected = (
        b'<record>\n'
        b'  <datafield tag="520" ind1=" " ind2=" ">\n'
        b'    <subfield code="9">submitter</subfield>\n'
        b'    <subfield code="a">A common feature shared by many quantum gravity models is modications of two-point functions at energy scales around the Planck scale.</subfield>\n'
        b'  </datafield>\n'
        b'</record>\n'
    )
    result = record2marcxml(record)

    assert expected == result
Esempio n. 15
0
def test_record2marcxml_raises_when_rules_were_not_implemented():
    record = {'$schema': 'http://localhost:5000/schemas/records/data.json'}

    with pytest.raises(NotImplementedError) as excinfo:
        record2marcxml(record)
    assert 'missing' in str(excinfo.value)
Esempio n. 16
0
def record_json_to_marcxml(pid, record, **kwargs):
    """Converts record to marcxml for OAI."""
    return ET.fromstring(record2marcxml(record["_source"]))