def test_lookup_equivalent_isbns(self): identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID) api = MockNoveListAPI.from_config(self._default_library) # If there are no ISBN equivalents, it returns None. eq_(None, api.lookup_equivalent_isbns(identifier)) source = DataSource.lookup(self._db, DataSource.OVERDRIVE) identifier.equivalent_to(source, self._identifier(), strength=1) self._db.commit() eq_(None, api.lookup_equivalent_isbns(identifier)) # If there's an ISBN equivalent, but it doesn't result in metadata, # it returns none. isbn = self._identifier(identifier_type=Identifier.ISBN) identifier.equivalent_to(source, isbn, strength=1) self._db.commit() api.responses.append(None) eq_(None, api.lookup_equivalent_isbns(identifier)) # Create an API class that can mockout NoveListAPI.choose_best_metadata class MockBestMetadataAPI(MockNoveListAPI): choose_best_metadata_return = None def choose_best_metadata(self, *args, **kwargs): return self.choose_best_metadata_return api = MockBestMetadataAPI.from_config(self._default_library) # Give the identifier another ISBN equivalent. isbn2 = self._identifier(identifier_type=Identifier.ISBN) identifier.equivalent_to(source, isbn2, strength=1) self._db.commit() # Queue metadata responses for each ISBN lookup. metadatas = [object(), object()] api.responses.extend(metadatas) # If choose_best_metadata returns None, the lookup returns None. api.choose_best_metadata_return = (None, None) eq_(None, api.lookup_equivalent_isbns(identifier)) # Lookup was performed for both ISBNs. eq_([], api.responses) # If choose_best_metadata returns a low confidence metadata, the # lookup returns None. api.responses.extend(metadatas) api.choose_best_metadata_return = (metadatas[0], 0.33) eq_(None, api.lookup_equivalent_isbns(identifier)) # If choose_best_metadata returns a high confidence metadata, the # lookup returns the metadata. api.responses.extend(metadatas) api.choose_best_metadata_return = (metadatas[1], 0.67) eq_(metadatas[1], api.lookup_equivalent_isbns(identifier))
def test_lookup_equivalent_isbns(self): identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID) api = MockNoveListAPI.from_config(self._default_library) # If there are no ISBN equivalents, it returns None. eq_(None, api.lookup_equivalent_isbns(identifier)) source = DataSource.lookup(self._db, DataSource.OVERDRIVE) identifier.equivalent_to(source, self._identifier(), strength=1) self._db.commit() eq_(None, api.lookup_equivalent_isbns(identifier)) # If there's an ISBN equivalent, but it doesn't result in metadata, # it returns none. isbn = self._identifier(identifier_type=Identifier.ISBN) identifier.equivalent_to(source, isbn, strength=1) self._db.commit() api.responses.append(None) eq_(None, api.lookup_equivalent_isbns(identifier)) # Create an API class that can mockout NoveListAPI.choose_best_metadata class MockBestMetadataAPI(MockNoveListAPI): choose_best_metadata_return = None def choose_best_metadata(self, *args, **kwargs): return self.choose_best_metadata_return api = MockBestMetadataAPI.from_config(self._default_library) # Give the identifier another ISBN equivalent. isbn2 = self._identifier(identifier_type=Identifier.ISBN) identifier.equivalent_to(source, isbn2, strength=1) self._db.commit() # Queue metadata responses for each ISBN lookup. metadatas = [object(), object()] api.responses.extend(metadatas) # If choose_best_metadata returns None, the lookup returns None. api.choose_best_metadata_return = (None, None) eq_(None, api.lookup_equivalent_isbns(identifier)) # Lookup was performed for both ISBNs. eq_([], api.responses) # If choose_best_metadata returns a low confidence metadata, the # lookup returns None. api.responses.extend(metadatas) api.choose_best_metadata_return = (metadatas[0], 0.33) eq_(None, api.lookup_equivalent_isbns(identifier)) # If choose_best_metadata returns a high confidence metadata, the # lookup returns the metadata. api.responses.extend(metadatas) api.choose_best_metadata_return = (metadatas[1], 0.67) eq_(metadatas[1], api.lookup_equivalent_isbns(identifier))
def setup(self): super(TestNoveListCoverageProvider, self).setup() self.integration = self._external_integration( ExternalIntegration.NOVELIST, ExternalIntegration.METADATA_GOAL, username=u'library', password=u'yep', libraries=[self._default_library]) self.novelist = NoveListCoverageProvider(self._db) self.novelist.api = MockNoveListAPI.from_config(self._default_library) self.metadata = Metadata(data_source=self.novelist.data_source, primary_identifier=self._identifier( identifier_type=Identifier.NOVELIST_ID), title=u"The Great American Novel")
def setup(self): super(TestNoveListCoverageProvider, self).setup() self.integration = self._external_integration( ExternalIntegration.NOVELIST, ExternalIntegration.METADATA_GOAL, username=u'library', password=u'yep', libraries=[self._default_library] ) self.novelist = NoveListCoverageProvider(self._db) self.novelist.api = MockNoveListAPI.from_config(self._default_library) self.metadata = Metadata( data_source = self.novelist.data_source, primary_identifier=self._identifier( identifier_type=Identifier.NOVELIST_ID ), title=u"The Great American Novel" )