Пример #1
0
 def refresh_availability(self, identifiers):
     provider = None
     identifier = identifiers[0]
     if identifier.type==Identifier.THREEM_ID:
         sweeper = BibliothecaCirculationSweep(self._db)
         sweeper.process_batch(identifiers)
     elif identifier.type==Identifier.OVERDRIVE_ID:
         api = OverdriveAPI(self._db)
         for identifier in identifiers:
             api.update_licensepool(identifier.identifier)
     elif identifier.type==Identifier.AXIS_360_ID:
         provider = Axis360BibliographicCoverageProvider(self._db)
         provider.process_batch(identifiers)
     else:
         self.log.warn("Cannot update coverage for %r" % identifier.type)
Пример #2
0
    def test_circulation_sweep_discovers_work(self):
        """Test what happens when BibliothecaCirculationSweep discovers a new
        work.
        """

        # Create an analytics integration so we can make sure
        # events are tracked.
        integration, ignore = create(
            self._db,
            ExternalIntegration,
            goal=ExternalIntegration.ANALYTICS_GOAL,
            protocol="core.local_analytics_provider",
        )

        # We know about an identifier, but nothing else.
        identifier = self._identifier(
            identifier_type=Identifier.BIBLIOTHECA_ID, foreign_id="d5rf89")

        # We're about to get information about that identifier from
        # the API.
        data = self.sample_data("item_circulation_single.xml")

        # Update availability using that data.
        self.api.queue_response(200, content=data)
        monitor = BibliothecaCirculationSweep(self._db,
                                              self.collection,
                                              api_class=self.api)
        monitor.process_items([identifier])

        # A LicensePool has been created for the previously mysterious
        # identifier.
        [pool] = identifier.licensed_through
        eq_(self.collection, pool.collection)
        eq_(False, pool.open_access)

        # Three circulation events were created for this license pool,
        # marking the creation of the license pool, the addition of
        # licenses owned, and the making of those licenses available.
        circulation_events = self._db.query(CirculationEvent).join(
            LicensePool).filter(LicensePool.id == pool.id)
        eq_(3, circulation_events.count())
        types = [e.type for e in circulation_events]
        eq_(
            sorted([
                CirculationEvent.DISTRIBUTOR_LICENSE_ADD,
                CirculationEvent.DISTRIBUTOR_TITLE_ADD,
                CirculationEvent.DISTRIBUTOR_CHECKIN
            ]), sorted(types))