Beispiel #1
0
    def test_process_book_updates_old_licensepool(self):
        """If the LicensePool already exists, the circulation monitor
        updates it.
        """
        edition, licensepool = self._edition(
            with_license_pool=True,
            identifier_type=Identifier.AXIS_360_ID,
            identifier_id=u'0003642860')
        # We start off with availability information based on the
        # default for test data.
        eq_(1, licensepool.licenses_owned)

        identifier = IdentifierData(
            type=licensepool.identifier.type,
            identifier=licensepool.identifier.identifier)
        metadata = Metadata(DataSource.AXIS_360, primary_identifier=identifier)
        monitor = Axis360CirculationMonitor(
            self._db,
            self.collection,
            api_class=MockAxis360API,
            metadata_client=MockMetadataWranglerOPDSLookup('url'))
        edition, licensepool = monitor.process_book(metadata,
                                                    self.AVAILABILITY_DATA)

        # Now we have information based on the CirculationData.
        eq_(9, licensepool.licenses_owned)
Beispiel #2
0
 def setup(self):
     super(MetadataWranglerCollectionManagerTest, self).setup()
     self.integration = self._external_integration(
         ExternalIntegration.METADATA_WRANGLER,
         goal=ExternalIntegration.METADATA_GOAL,
         url=self._url,
         username=u'abc',
         password=u'def')
     self.source = DataSource.lookup(self._db, DataSource.METADATA_WRANGLER)
     self.collection = self._collection(
         protocol=ExternalIntegration.BIBLIOTHECA,
         external_account_id=u'lib')
     self.lookup = MockMetadataWranglerOPDSLookup.from_config(
         self._db, collection=self.collection)
 def setup(self):
     super(MetadataWranglerCollectionManagerTest, self).setup()
     self.integration = self._external_integration(
         ExternalIntegration.METADATA_WRANGLER,
         goal=ExternalIntegration.METADATA_GOAL, url=self._url,
         username=u'abc', password=u'def'
     )
     self.source = DataSource.lookup(self._db, DataSource.METADATA_WRANGLER)
     self.collection = self._collection(
         protocol=ExternalIntegration.BIBLIOTHECA, external_account_id=u'lib'
     )
     self.lookup = MockMetadataWranglerOPDSLookup.from_config(
         self._db, collection=self.collection
     )
Beispiel #4
0
    def setup(self):
        super(TestMWCollectionUpdateMonitor, self).setup()
        self._external_integration(ExternalIntegration.METADATA_WRANGLER,
                                   ExternalIntegration.METADATA_GOAL,
                                   username=u'abc',
                                   password=u'def',
                                   url=self._url)

        self.collection = self._collection(
            protocol=ExternalIntegration.BIBLIOTHECA,
            external_account_id=u'lib')

        self.lookup = MockMetadataWranglerOPDSLookup.from_config(
            self._db, self.collection)

        self.monitor = InstrumentedMWCollectionUpdateMonitor(
            self._db, self.collection, self.lookup)
    def setup(self):
        super(TestMWCollectionUpdateMonitor, self).setup()
        self._external_integration(
            ExternalIntegration.METADATA_WRANGLER,
            ExternalIntegration.METADATA_GOAL,
            username=u'abc', password=u'def', url=self._url
        )

        self.collection = self._collection(
            protocol=ExternalIntegration.BIBLIOTHECA, external_account_id=u'lib'
        )

        self.lookup = MockMetadataWranglerOPDSLookup.from_config(
            self._db, self.collection
        )

        self.monitor = InstrumentedMWCollectionUpdateMonitor(
            self._db, self.collection, self.lookup
        )
Beispiel #6
0
    def setup(self):
        super(TestMWAuxiliaryMetadataMonitor, self).setup()

        self._external_integration(ExternalIntegration.METADATA_WRANGLER,
                                   ExternalIntegration.METADATA_GOAL,
                                   username=u'abc',
                                   password=u'def',
                                   url=self._url)

        self.collection = self._collection(
            protocol=ExternalIntegration.OVERDRIVE, external_account_id=u'lib')

        self.lookup = MockMetadataWranglerOPDSLookup.from_config(
            self._db, self.collection)

        provider = AlwaysSuccessfulCoverageProvider(self._db)

        self.monitor = MWAuxiliaryMetadataMonitor(self._db,
                                                  self.collection,
                                                  lookup=self.lookup,
                                                  provider=provider)
Beispiel #7
0
    def test_run_once(self):
        # Setup authentication and Metadata Wrangler details.
        self._external_integration(ExternalIntegration.METADATA_WRANGLER,
                                   ExternalIntegration.METADATA_GOAL,
                                   username=u'abc',
                                   password=u'def',
                                   url=self._url)

        # Create an identifier and its equivalent to work with the OPDS
        # feed.
        collection = self._collection(protocol=ExternalIntegration.BIBLIOTHECA,
                                      external_account_id=u'lib')
        lp = self._licensepool(None,
                               data_source_name=DataSource.BIBLIOTHECA,
                               collection=collection)
        lp.identifier.type = Identifier.BIBLIOTHECA_ID
        isbn = Identifier.parse_urn(self._db, u'urn:isbn:9781594632556')[0]
        lp.identifier.equivalent_to(
            DataSource.lookup(self._db, DataSource.BIBLIOTHECA), isbn, 1)
        eq_([], lp.identifier.links)
        eq_([], lp.identifier.measurements)

        # Queue some data to be found.
        data = sample_data('metadata_isbn_response.opds', 'opds')
        lookup = MockMetadataWranglerOPDSLookup.from_config(
            self._db, collection)
        lookup.queue_response(200,
                              {'content-type': OPDSFeed.ACQUISITION_FEED_TYPE},
                              data)

        monitor = MetadataWranglerCollectionUpdateMonitor(
            self._db, collection, lookup)
        monitor.run_once(None, None)

        # The original Identifier has information from the
        # mock Metadata Wrangler.
        mw_source = DataSource.lookup(self._db, DataSource.METADATA_WRANGLER)
        eq_(3, len(lp.identifier.links))
        [quality] = lp.identifier.measurements
        eq_(mw_source, quality.data_source)
    def setup(self):
        super(TestMWAuxiliaryMetadataMonitor, self).setup()

        self._external_integration(
            ExternalIntegration.METADATA_WRANGLER,
            ExternalIntegration.METADATA_GOAL,
            username=u'abc', password=u'def', url=self._url
        )

        self.collection = self._collection(
            protocol=ExternalIntegration.OVERDRIVE, external_account_id=u'lib'
        )

        self.lookup = MockMetadataWranglerOPDSLookup.from_config(
            self._db, self.collection
        )

        provider = AlwaysSuccessfulCoverageProvider(self._db)

        self.monitor = MWAuxiliaryMetadataMonitor(
            self._db, self.collection, lookup=self.lookup, provider=provider
        )
Beispiel #9
0
    def test_process_book(self):
        integration, ignore = create(
            self._db,
            ExternalIntegration,
            goal=ExternalIntegration.ANALYTICS_GOAL,
            protocol="core.local_analytics_provider",
        )

        monitor = Axis360CirculationMonitor(
            self._db,
            self.collection,
            api_class=MockAxis360API,
            metadata_client=MockMetadataWranglerOPDSLookup('url'))
        edition, license_pool = monitor.process_book(self.BIBLIOGRAPHIC_DATA,
                                                     self.AVAILABILITY_DATA)
        eq_(u'Faith of My Fathers : A Family Memoir', edition.title)
        eq_(u'eng', edition.language)
        eq_(u'Random House Inc', edition.publisher)
        eq_(u'Random House Inc2', edition.imprint)

        eq_(Identifier.AXIS_360_ID, edition.primary_identifier.type)
        eq_(u'0003642860', edition.primary_identifier.identifier)

        [isbn] = [
            x for x in edition.equivalent_identifiers()
            if x is not edition.primary_identifier
        ]
        eq_(Identifier.ISBN, isbn.type)
        eq_(u'9780375504587', isbn.identifier)

        eq_(
            ["McCain, John", "Salter, Mark"],
            sorted([x.sort_name for x in edition.contributors]),
        )

        subs = sorted((x.subject.type, x.subject.identifier)
                      for x in edition.primary_identifier.classifications)
        eq_([(Subject.BISAC, u'BIOGRAPHY & AUTOBIOGRAPHY / Political'),
             (Subject.FREEFORM_AUDIENCE, u'Adult')], subs)

        eq_(9, license_pool.licenses_owned)
        eq_(8, license_pool.licenses_available)
        eq_(0, license_pool.patrons_in_hold_queue)
        eq_(datetime.datetime(2015, 5, 20, 2, 9, 8), license_pool.last_checked)

        # Three circulation events were created, backdated to the
        # last_checked date of the license pool.
        events = license_pool.circulation_events
        eq_([
            u'distributor_title_add', u'distributor_check_in',
            u'distributor_license_add'
        ], [x.type for x in events])
        for e in events:
            eq_(e.start, license_pool.last_checked)

        # A presentation-ready work has been created for the LicensePool.
        work = license_pool.work
        eq_(True, work.presentation_ready)
        eq_("Faith of My Fathers : A Family Memoir", work.title)

        # A CoverageRecord has been provided for this book in the Axis
        # 360 bibliographic coverage provider, so that in the future
        # it doesn't have to make a separate API request to ask about
        # this book.
        records = [
            x for x in license_pool.identifier.coverage_records if
            x.data_source.name == DataSource.AXIS_360 and x.operation is None
        ]
        eq_(1, len(records))
Beispiel #10
0
 def create_provider(self, **kwargs):
     lookup = MockMetadataWranglerOPDSLookup.from_config(
         self._db, self.collection)
     return MetadataWranglerCoverageProvider(self.collection, lookup,
                                             **kwargs)
Beispiel #11
0
 def create_provider(self, **kwargs):
     upload_client = MockMetadataWranglerOPDSLookup.from_config(
         self._db, self.collection)
     return MetadataUploadCoverageProvider(self.collection, upload_client,
                                           **kwargs)
 def create_provider(self, **kwargs):
     upload_client = MockMetadataWranglerOPDSLookup.from_config(self._db, self.collection)
     return MetadataUploadCoverageProvider(
         self.collection, upload_client, **kwargs
     )
 def create_provider(self, **kwargs):
     lookup = MockMetadataWranglerOPDSLookup.from_config(self._db, self.collection)
     return self.TEST_CLASS(self.collection, lookup, **kwargs)