Beispiel #1
0
def test_nonexistent_style():
    """Test Citeproc exceptions."""
    pid, record = get_test_data()

    serializer = CiteprocSerializer(TestSerializer())
    with pytest.raises(StyleNotFoundError):
        serializer.serialize(pid, record, style='non-existent')
Beispiel #2
0
def test_serialize():
    """Test Citeproc serialization."""
    pid, record = get_test_data()

    serializer = CiteprocSerializer(TestSerializer())
    data = serializer.serialize(pid, record)
    assert 'Citeproc test' in data
    assert 'Doe, J.' in data
    assert '& Smith, J.' in data
    assert '2016.' in data
Beispiel #3
0
def test_serializer_args():
    """Test Citeproc serialization arguments."""
    pid, record = get_test_data()

    serializer = CiteprocSerializer(TestSerializer())
    data = serializer.serialize(pid, record, style='science')
    assert '1.' in data
    assert 'J. Doe,' in data
    assert 'J. Smith,' in data
    assert 'Citeproc test' in data
    assert '(2016)' in data
Beispiel #4
0
def test_serializer_in_request(app):
    """Test Citeproc serialization while in a request context."""
    pid, record = get_test_data()

    serializer = CiteprocSerializer(TestSerializer())

    with app.test_request_context(query_string={'style': 'science'}):
        data = serializer.serialize(pid, record)
        assert '1.' in data
        assert 'J. Doe,' in data
        assert 'J. Smith,' in data
        assert 'Citeproc test' in data
        assert '(2016)' in data

    with app.test_request_context(query_string={'style': 'non-existent'}):
        with pytest.raises(StyleNotFoundRESTError):
            serializer.serialize(pid, record, style='non-existent')
Beispiel #5
0
    to_marc21, schema_class=RecordSchemaMARC21, replace_refs=True)
#: BibTeX serializer version 1.0.0
bibtex_v1 = BibTeXSerializer()
#: DataCite serializer
datacite_v31 = ZenodoDataCite31Serializer(DataCiteSchemaV1, replace_refs=True)
#: OAI DataCite serializer
oai_datacite = OAIDataCiteSerializer(
    serializer=datacite_v31,
    datacentre='CERN.ZENODO',
)
#: Dublin Core serializer
dc_v1 = ZenodoDublinCoreSerializer(DublinCoreV1, replace_refs=True)
#: CSL-JSON serializer
csl_v1 = JSONSerializer(RecordSchemaCSLJSON, replace_refs=True)
#: CSL Citation Formatter serializer
citeproc_v1 = CiteprocSerializer(csl_v1)
#: OpenAIRE JSON serializer
openaire_json_v1 = JSONSerializer(RecordSchemaOpenAIREJSON, replace_refs=True)
#: JSON-LD serializer
schemaorg_jsonld_v1 = ZenodoSchemaOrgSerializer(replace_refs=True)


# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record legacy serializer for individual records.
legacyjson_v1_response = record_responsify(legacyjson_v1, 'application/json')
#: MARCXML record serializer for individual records.
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')
#: BibTeX record serializer for individual records.
Beispiel #6
0
"""Record serializers."""

from invenio_records_rest.serializers.citeproc import CiteprocSerializer
from invenio_records_rest.serializers.response import (record_responsify,
                                                       search_responsify)

from ..marshmallow import CSLRecordSchemaV1, RecordSchemaV1
from .json import MenRvaJSONSerializer

# Serializers
# ===========
#: JSON serializer definition.
json_v1 = MenRvaJSONSerializer(RecordSchemaV1, replace_refs=True)

#: CSL Citation Formatter serializer
citeproc_v1 = CiteprocSerializer(
    MenRvaJSONSerializer(CSLRecordSchemaV1, replace_refs=True))

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')

__all__ = (
    'citeproc_v1',
    'json_v1',
    'json_v1_response',
    'json_v1_search',
)