Beispiel #1
0
    def test_book_info_to_metadata(self):
        oclc = OCLCLinkedData(self._db)
        subgraph = json.loads(self.sample_data("galapagos.jsonld"))['@graph']
        [book] = [book for book in oclc.books(subgraph)]

        metadata_obj = OCLCLinkedData(self._db).book_info_to_metadata(
            subgraph, book)

        # A metadata object is returned, with the proper OCLC identifier.
        eq_(True, isinstance(metadata_obj, Metadata))
        eq_(Identifier.OCLC_NUMBER, metadata_obj.primary_identifier.type)
        eq_(u"11866009", metadata_obj.primary_identifier.identifier)

        # It has publication information & ISBNs
        eq_(u"Galápagos : a novel", metadata_obj.title)
        eq_(u'Delacorte Press/Seymour Lawrence', metadata_obj.publisher)
        eq_(1985, metadata_obj.published.year)
        eq_(1, len(metadata_obj.links))
        assert "ghost of a shipbuilder" in metadata_obj.links[0].content
        eq_(4, len(metadata_obj.identifiers))

        eq_(1, len(metadata_obj.contributors))
        [viaf] = [c.viaf for c in metadata_obj.contributors]
        eq_(u"71398958", viaf)
        eq_(10, len(metadata_obj.subjects))

        # Make sure a book with no English title doesn't break anything.
        subgraph[14]['name']['@language'] = 'fr'
        [book] = [book for book in oclc.books(subgraph)]

        metadata_obj = OCLCLinkedData(self._db).book_info_to_metadata(
            subgraph, book)

        # The metadata has no title.
        eq_(None, metadata_obj.title)
Beispiel #2
0
 def __init__(self, _db, oclcld=None, viaf=None):
     self._db = _db
     self.oclcld = oclcld or OCLCLinkedData(_db)
     self.viaf = viaf or VIAFClient(_db)
     self.log = logging.getLogger("Author name canonicalizer")