예제 #1
0
def test_serialize_search():
    """Test MARCXML serialize."""
    def fetcher(obj_uuid, data):
        return PersistentIdentifier(pid_type='recid', pid_value=data['pid'])

    s = MARCXMLSerializer(to_marc21, schema_class=MySchema)
    data = s.serialize_search(
        fetcher,
        dict(
            hits=dict(
                hits=[
                    {'_source': dict(pid='1'), '_id': 'a', '_version': 1},
                    {'_source': dict(pid='2'), '_id': 'b', '_version': 1},
                ],
                total=2,
            ),
            aggregations={},
        )
    )
    expected = u"<?xml version='1.0' encoding='UTF-8'?>\n" \
               u'<collection xmlns="http://www.loc.gov/MARC21/slim">\n' \
               u'  <record>\n' \
               u'    <controlfield tag="001">1</controlfield>\n' \
               u'  </record>\n' \
               u'  <record>\n' \
               u'    <controlfield tag="001">2</controlfield>\n' \
               u'  </record>\n' \
               u'</collection>\n'
    assert data.decode('utf8') == expected
def test_serialize_oaipmh():
    """Test MARCXML serialize."""
    s = MARCXMLSerializer(to_marc21, schema_class=MySchema)

    tree = s.serialize_oaipmh(
        PersistentIdentifier(pid_type='recid', pid_value='2'),
        {'_source': Record({'title': 'test'})})

    assert tree.getchildren()[0].text == '2'
def test_serialize_oaipmh():
    """Test MARCXML serialize."""
    s = MARCXMLSerializer(to_marc21, schema_class=MySchema)

    tree = s.serialize_oaipmh(
        PersistentIdentifier(pid_type='recid', pid_value='2'),
        {'_source': Record({'title': 'test'})})

    assert tree.getchildren()[0].text == '2'
def test_serialize(app):
    """Test JSON serialize."""
    data = MARCXMLSerializer(to_marc21, schema_class=MySchema).serialize(
        PersistentIdentifier(pid_type='recid', pid_value='2'),
        Record({'title': 'test'}))
    expected = u"<?xml version='1.0' encoding='UTF-8'?>\n" \
               u'<record xmlns="http://www.loc.gov/MARC21/slim">\n' \
               u'  <controlfield tag="001">2</controlfield>\n' \
               u'</record>\n'
    assert data.decode('utf8') == expected
예제 #5
0
def test_serialize_oaipmh():
    """Test MARCXML serialize."""
    s = MARCXMLSerializer(to_marc21, schema_class=MySchema)

    tree = s.serialize_oaipmh(
        PersistentIdentifier(pid_type="recid", pid_value="2"),
        {"_source": Record({"title": "test"})},
    )

    assert tree.getchildren()[0].text == "2"
예제 #6
0
def test_serialize(app):
    """Test JSON serialize."""
    data = MARCXMLSerializer(to_marc21, schema_class=MySchema).serialize(
        PersistentIdentifier(pid_type="recid", pid_value="2"),
        Record({"title": "test"}))
    expected = (u"<?xml version='1.0' encoding='UTF-8'?>\n"
                u'<record xmlns="http://www.loc.gov/MARC21/slim">\n'
                u'  <controlfield tag="001">2</controlfield>\n'
                u"</record>\n")
    assert data.decode("utf8") == expected
def test_serialize(app):
    """Test JSON serialize."""
    data = MARCXMLSerializer(to_marc21, schema_class=MySchema).serialize(
        PersistentIdentifier(pid_type='recid', pid_value='2'),
        Record({'title': 'test'}))
    expected = u"<?xml version='1.0' encoding='UTF-8'?>\n" \
               u'<record xmlns="http://www.loc.gov/MARC21/slim">\n' \
               u'  <controlfield tag="001">2</controlfield>\n' \
               u'</record>\n'
    assert data.decode('utf8') == expected
예제 #8
0
def test_serialize_no_schema_class():
    """Test MARCXML serialization without providing record schema."""
    s = MARCXMLSerializer(to_marc21)
    rec = Record({'__order__': ['control_number_identifier'],
                  'control_number_identifier': 'SzGeCERN'})
    data = s.serialize(PersistentIdentifier(pid_type='recid', pid_value='1'),
                       rec)
    expected = u'<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n' \
               u'<record xmlns="http://www.loc.gov/MARC21/slim">\n' \
               u'  <controlfield tag="003">SzGeCERN</controlfield>\n' \
               u'</record>\n'
    assert data.decode('utf8') == expected
예제 #9
0
def test_serialize_no_schema_class():
    """Test MARCXML serialization without providing record schema."""
    s = MARCXMLSerializer(to_marc21)
    rec = Record({
        "__order__": ["control_number_identifier"],
        "control_number_identifier": "SzGeCERN",
    })
    data = s.serialize(PersistentIdentifier(pid_type="recid", pid_value="1"),
                       rec)
    expected = (u"<?xml version='1.0' encoding='UTF-8'?>\n"
                u'<record xmlns="http://www.loc.gov/MARC21/slim">\n'
                u'  <controlfield tag="003">SzGeCERN</controlfield>\n'
                u"</record>\n")
    assert data.decode("utf8") == expected
예제 #10
0
def test_serialize_search():
    """Test MARCXML serialize."""
    def fetcher(obj_uuid, data):
        return PersistentIdentifier(pid_type="recid", pid_value=data["pid"])

    s = MARCXMLSerializer(to_marc21, schema_class=MySchema)
    data = s.serialize_search(
        fetcher,
        dict(
            hits=dict(
                hits=[
                    {
                        "_source": dict(pid="1"),
                        "_id": "a",
                        "_version": 1
                    },
                    {
                        "_source": dict(pid="2"),
                        "_id": "b",
                        "_version": 1
                    },
                ],
                total=2,
            ),
            aggregations={},
        ),
    )
    expected = (u"<?xml version='1.0' encoding='UTF-8'?>\n"
                u'<collection xmlns="http://www.loc.gov/MARC21/slim">\n'
                u"  <record>\n"
                u'    <controlfield tag="001">1</controlfield>\n'
                u"  </record>\n"
                u"  <record>\n"
                u'    <controlfield tag="001">2</controlfield>\n'
                u"  </record>\n"
                u"</collection>\n")
    assert data.decode("utf8") == expected
예제 #11
0
json_v1 = JSONSerializer(RecordSchemaV1, replace_refs=True)
#: Zenodo Deposit JSON serializer version 1.0.0
deposit_json_v1 = JSONSerializer(DepositSchemaV1, replace_refs=True)
#: Zenodo legacy deposit JSON serialzier version 1.0.0
legacyjson_v1 = LegacyJSONSerializer(LegacyRecordSchemaV1, replace_refs=True)
#: Zenodo legacy deposit JSON serialzier version 1.0.0
githubjson_v1 = LegacyJSONSerializer(GitHubRecordSchemaV1, replace_refs=True)
#: Deposit form JSON serialzier version 1.0.0
deposit_formjson_v1 = LegacyJSONSerializer(DepositFormSchemaV1,
                                           replace_refs=True)
#: Zenodo legacy deposit JSON serialzier version 1.0.0
deposit_legacyjson_v1 = DepositLegacyJSONSerializer(LegacyRecordSchemaV1,
                                                    replace_refs=True)
#: MARCXML serializer version 1.0.0
marcxml_v1 = MARCXMLSerializer(to_marc21,
                               schema_class=RecordSchemaMARC21,
                               replace_refs=True)
#: BibTeX serializer version 1.0.0
bibtex_v1 = BibTeXSerializer()
#: DataCite serializer
datacite_v31 = DataCite31Serializer(DataCiteSchemaV1, replace_refs=True)
#: OAI DataCite serializer
oai_datacite = OAIDataCiteSerializer(
    v31=datacite_v31,
    datacentre='CERN.ZENODO',
)
#: Dublin Core serializer
dc_v1 = DublinCoreSerializer(DublinCoreV1, replace_refs=True)
#: CSL-JSON serializer
csl_v1 = JSONSerializer(RecordSchemaCSLJSON, replace_refs=True)
#: CSL Citation Formatter serializer