Exemplo n.º 1
0
    def test_reaper(self):
        feed = self.get_data("biblioboard_mini_feed.opds")

        class MockOPDSForDistributorsReaperMonitor(
                OPDSForDistributorsReaperMonitor):
            """An OPDSForDistributorsReaperMonitor that overrides _get."""
            def _get(self, url, headers):
                return 200, {}, feed

        data_source = DataSource.lookup(self._db,
                                        "Biblioboard",
                                        autocreate=True)
        collection = MockOPDSForDistributorsAPI.mock_collection(self._db)
        collection.external_integration.set_setting(
            Collection.DATA_SOURCE_NAME_SETTING, data_source.name)
        monitor = MockOPDSForDistributorsReaperMonitor(
            self._db,
            collection,
            OPDSForDistributorsImporter,
            metadata_client=object())

        # There's a license pool in the database that isn't in the feed anymore.
        edition, pool = self._edition(
            identifier_type=Identifier.URI,
            data_source_name=data_source.name,
            with_license_pool=True,
            collection=collection,
        )
        pool.licenses_owned = 1
        pool.licenses_available = 1

        monitor.run_once(None, None)

        eq_(0, pool.licenses_owned)
        eq_(0, pool.licenses_available)
Exemplo n.º 2
0
    def test_import(self):
        feed = self.get_data("biblioboard_mini_feed.opds")

        data_source = DataSource.lookup(self._db, "Biblioboard", autocreate=True)
        collection = MockOPDSForDistributorsAPI.mock_collection(self._db)
        collection.external_integration.set_setting(
            Collection.DATA_SOURCE_NAME_SETTING,
            data_source.name
        )

        class MockMetadataClient(object):
            def canonicalize_author_name(self, identifier, working_display_name):
                return working_display_name
        metadata_client = MockMetadataClient()
        importer = OPDSForDistributorsImporter(
            self._db, collection=collection,
            metadata_client=metadata_client,
        )

        imported_editions, imported_pools, imported_works, failures = (
            importer.import_from_feed(feed)
        )

        # This importer works the same as the base OPDSImporter, except that
        # it adds delivery mechanisms for books with epub acquisition links
        # and sets pools' licenses_owned and licenses_available.

        # Both works were created, since we can use their acquisition links
        # to give copies to patrons.
        [camelot, southern] = sorted(imported_works, key=lambda x: x.title)

        # Each work has a license pool.
        [camelot_pool] = camelot.license_pools
        [southern_pool] = southern.license_pools

        for pool in [camelot_pool, southern_pool]:
            eq_(False, pool.open_access)
            eq_(RightsStatus.IN_COPYRIGHT, pool.delivery_mechanisms[0].rights_status.uri)
            eq_(Representation.EPUB_MEDIA_TYPE, pool.delivery_mechanisms[0].delivery_mechanism.content_type)
            eq_(DeliveryMechanism.NO_DRM, pool.delivery_mechanisms[0].delivery_mechanism.drm_scheme)
            eq_(1, pool.licenses_owned)
            eq_(1, pool.licenses_available)

        [camelot_acquisition_link] = [l for l in camelot_pool.identifier.links
                                      if l.rel == Hyperlink.GENERIC_OPDS_ACQUISITION
                                      and l.resource.representation.media_type == Representation.EPUB_MEDIA_TYPE]
        camelot_acquisition_url = camelot_acquisition_link.resource.representation.url
        eq_("https://library.biblioboard.com/ext/api/media/04377e87-ab69-41c8-a2a4-812d55dc0952/assets/content.epub",
            camelot_acquisition_url)

        [southern_acquisition_link] = [l for l in southern_pool.identifier.links
                                      if l.rel == Hyperlink.GENERIC_OPDS_ACQUISITION
                                      and l.resource.representation.media_type == Representation.EPUB_MEDIA_TYPE]
        southern_acquisition_url = southern_acquisition_link.resource.representation.url
        eq_("https://library.biblioboard.com/ext/api/media/04da95cd-6cfc-4e82-810f-121d418b6963/assets/content.epub",
            southern_acquisition_url)
Exemplo n.º 3
0
    def test_reaper(self):
        feed = self.get_data("biblioboard_mini_feed.opds")

        class MockOPDSForDistributorsReaperMonitor(
                OPDSForDistributorsReaperMonitor):
            """An OPDSForDistributorsReaperMonitor that overrides _get."""
            def _get(self, url, headers):
                return (200, {
                    'content-type': OPDSFeed.ACQUISITION_FEED_TYPE
                }, feed)

        data_source = DataSource.lookup(self._db,
                                        "Biblioboard",
                                        autocreate=True)
        collection = MockOPDSForDistributorsAPI.mock_collection(self._db)
        collection.external_integration.set_setting(
            Collection.DATA_SOURCE_NAME_SETTING, data_source.name)
        monitor = MockOPDSForDistributorsReaperMonitor(
            self._db,
            collection,
            OPDSForDistributorsImporter,
            metadata_client=object())

        # There's a license pool in the database that isn't in the feed anymore.
        edition, pool = self._edition(
            identifier_type=Identifier.URI,
            data_source_name=data_source.name,
            with_license_pool=True,
            collection=collection,
        )
        pool.licenses_owned = 1
        pool.licenses_available = 1

        progress = monitor.run_once(monitor.timestamp().to_data())

        eq_(0, pool.licenses_owned)
        eq_(0, pool.licenses_available)

        # The TimestampData returned by run_once() describes its
        # achievements.
        eq_("License pools removed: 1.", progress.achievements)

        # The TimestampData does not include any timing information --
        # that will be applied by run().
        eq_(None, progress.start)
        eq_(None, progress.finish)
Exemplo n.º 4
0
 def setup(self):
     super(TestOPDSForDistributorsAPI, self).setup()
     self.collection = MockOPDSForDistributorsAPI.mock_collection(self._db)
     self.api = MockOPDSForDistributorsAPI(self._db, self.collection)
Exemplo n.º 5
0
    def test_reaper(self):
        feed = self.get_data("biblioboard_mini_feed.opds")

        class MockOPDSForDistributorsReaperMonitor(
                OPDSForDistributorsReaperMonitor):
            """An OPDSForDistributorsReaperMonitor that overrides _get."""
            def _get(self, url, headers):
                return (200, {
                    "content-type": OPDSFeed.ACQUISITION_FEED_TYPE
                }, feed)

        data_source = DataSource.lookup(self._db,
                                        "Biblioboard",
                                        autocreate=True)
        collection = MockOPDSForDistributorsAPI.mock_collection(self._db)
        collection.external_integration.set_setting(
            Collection.DATA_SOURCE_NAME_SETTING, data_source.name)
        monitor = MockOPDSForDistributorsReaperMonitor(
            self._db,
            collection,
            OPDSForDistributorsImporter,
            metadata_client=object())

        # There's a license pool in the database that isn't in the feed anymore.
        edition, now_gone = self._edition(
            identifier_type=Identifier.URI,
            data_source_name=data_source.name,
            with_license_pool=True,
            collection=collection,
        )
        now_gone.licenses_owned = 1
        now_gone.licenses_available = 1

        edition, still_there = self._edition(
            identifier_type=Identifier.URI,
            identifier_id="urn:uuid:04377e87-ab69-41c8-a2a4-812d55dc0952",
            data_source_name=data_source.name,
            with_license_pool=True,
            collection=collection,
        )
        still_there.licenses_owned = 1
        still_there.licenses_available = 1

        progress = monitor.run_once(monitor.timestamp().to_data())

        # One LicensePool has been cleared out.
        assert 0 == now_gone.licenses_owned
        assert 0 == now_gone.licenses_available

        # The other is still around.
        assert 1 == still_there.licenses_owned
        assert 1 == still_there.licenses_available

        # The TimestampData returned by run_once() describes its
        # achievements.
        assert "License pools removed: 1." == progress.achievements

        # The TimestampData does not include any timing information --
        # that will be applied by run().
        assert None == progress.start
        assert None == progress.finish