Exemple #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
Exemple #2
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