Пример #1
0
    def test_feed_includes_refresh_link(self):
        work = self._work(with_open_access_download=True)
        lp = work.license_pools[0]
        lp.suppressed = False
        self._db.commit()

        # If the metadata wrangler isn't configured, the link is left out.
        feed = AcquisitionFeed(
            self._db, "test", "url", [work],
            AdminAnnotator(None, self._default_library, test_mode=True))
        [entry] = feedparser.parse(unicode(feed))['entries']
        eq_([], [
            x for x in entry['links']
            if x['rel'] == "http://librarysimplified.org/terms/rel/refresh"
        ])

        # If we configure a metadata wrangler integration, the link appears.
        integration = self._external_integration(
            ExternalIntegration.METADATA_WRANGLER,
            goal=ExternalIntegration.METADATA_GOAL,
            settings={ExternalIntegration.URL: "http://metadata"},
            password="******")
        integration.collections += [self._default_collection]
        feed = AcquisitionFeed(
            self._db, "test", "url", [work],
            AdminAnnotator(None, self._default_library, test_mode=True))
        [entry] = feedparser.parse(unicode(feed))['entries']
        [refresh_link] = [
            x for x in entry['links']
            if x['rel'] == "http://librarysimplified.org/terms/rel/refresh"
        ]
        assert lp.identifier.identifier in refresh_link["href"]
Пример #2
0
    def test_feed_includes_change_cover_link(self):
        work = self._work(with_open_access_download=True)
        lp = work.license_pools[0]
        library = self._default_library

        feed = AcquisitionFeed(
            self._db,
            "test",
            "url",
            [work],
            AdminAnnotator(None, library, test_mode=True),
        )
        [entry] = feedparser.parse(str(feed))["entries"]

        # Since there's no storage integration, the change cover link isn't included.
        assert [] == [
            x
            for x in entry["links"]
            if x["rel"] == "http://librarysimplified.org/terms/rel/change_cover"
        ]

        # There is now a covers storage integration that is linked to the external
        # integration for a collection that the work is in. It will use that
        # covers mirror and the change cover link is included.
        storage = self._external_integration(
            ExternalIntegration.S3, ExternalIntegration.STORAGE_GOAL
        )
        storage.username = "******"
        storage.password = "******"

        collection = self._collection()
        purpose = ExternalIntegrationLink.COVERS
        external_integration_link = self._external_integration_link(
            integration=collection._external_integration,
            other_integration=storage,
            purpose=purpose,
        )
        library.collections.append(collection)
        work = self._work(with_open_access_download=True, collection=collection)
        lp = work.license_pools[0]
        feed = AcquisitionFeed(
            self._db,
            "test",
            "url",
            [work],
            AdminAnnotator(None, library, test_mode=True),
        )
        [entry] = feedparser.parse(str(feed))["entries"]

        [change_cover_link] = [
            x
            for x in entry["links"]
            if x["rel"] == "http://librarysimplified.org/terms/rel/change_cover"
        ]
        assert lp.identifier.identifier in change_cover_link["href"]
Пример #3
0
    def test_feed_includes_suppress_link(self):
        work = self._work(with_open_access_download=True)
        lp = work.license_pools[0]
        lp.suppressed = False
        self._db.commit()

        feed = AcquisitionFeed(
            self._db,
            "test",
            "url",
            [work],
            AdminAnnotator(None, self._default_library, test_mode=True),
        )
        [entry] = feedparser.parse(str(feed))["entries"]
        [suppress_link] = [
            x
            for x in entry["links"]
            if x["rel"] == "http://librarysimplified.org/terms/rel/hide"
        ]
        assert lp.identifier.identifier in suppress_link["href"]
        unsuppress_links = [
            x
            for x in entry["links"]
            if x["rel"] == "http://librarysimplified.org/terms/rel/restore"
        ]
        assert 0 == len(unsuppress_links)

        lp.suppressed = True
        self._db.commit()

        feed = AcquisitionFeed(
            self._db,
            "test",
            "url",
            [work],
            AdminAnnotator(None, self._default_library, test_mode=True),
        )
        [entry] = feedparser.parse(str(feed))["entries"]
        [unsuppress_link] = [
            x
            for x in entry["links"]
            if x["rel"] == "http://librarysimplified.org/terms/rel/restore"
        ]
        assert lp.identifier.identifier in unsuppress_link["href"]
        suppress_links = [
            x
            for x in entry["links"]
            if x["rel"] == "http://librarysimplified.org/terms/rel/hide"
        ]
        assert 0 == len(suppress_links)
Пример #4
0
    def test_feed_includes_edit_link(self):
        work = self._work(with_open_access_download=True)
        lp = work.license_pools[0]
 
        feed = AcquisitionFeed(self._db, "test", "url", [work], AdminAnnotator(None, self._default_library, test_mode=True))
        [entry] = feedparser.parse(unicode(feed))['entries']
        [edit_link] = [x for x in entry['links'] if x['rel'] == "edit"]
        assert lp.identifier.identifier in edit_link["href"]
Пример #5
0
    def test_feed_includes_change_cover_link(self):
        work = self._work(with_open_access_download=True)
        lp = work.license_pools[0]
 
        feed = AcquisitionFeed(self._db, "test", "url", [work], AdminAnnotator(None, self._default_library, test_mode=True))
        [entry] = feedparser.parse(unicode(feed))['entries']

        # Since there's no storage integration, the change cover link isn't included.
        eq_([], [x for x in entry['links'] if x['rel'] == "http://librarysimplified.org/terms/rel/change_cover"])

        storage = self._external_integration(ExternalIntegration.S3, ExternalIntegration.STORAGE_GOAL)
        storage.username = "******"
        storage.password = "******"

        feed = AcquisitionFeed(self._db, "test", "url", [work], AdminAnnotator(None, self._default_library, test_mode=True))
        [entry] = feedparser.parse(unicode(feed))['entries']

        [change_cover_link] = [x for x in entry['links'] if x['rel'] == "http://librarysimplified.org/terms/rel/change_cover"]
        assert lp.identifier.identifier in change_cover_link["href"]
Пример #6
0
    def test_feed_includes_staff_rating(self):
        work = self._work(with_open_access_download=True)
        lp = work.license_pools[0]
        staff_data_source = DataSource.lookup(self._db, DataSource.LIBRARY_STAFF)
        lp.identifier.add_measurement(staff_data_source, Measurement.RATING, 3, weight=1000)

        feed = AcquisitionFeed(self._db, "test", "url", [work], AdminAnnotator(None, self._default_library, test_mode=True))
        [entry] = feedparser.parse(unicode(feed))['entries']
        rating = entry['schema_rating']
        eq_(3, float(rating['schema:ratingvalue']))
        eq_(Measurement.RATING, rating['additionaltype'])
Пример #7
0
    def details(self, identifier_type, identifier):
        """Return an OPDS entry with detailed information for admins.

        This includes relevant links for editing the book.
        """
        self.require_librarian(flask.request.library)

        work = self.load_work(flask.request.library, identifier_type,
                              identifier)
        if isinstance(work, ProblemDetail):
            return work

        annotator = AdminAnnotator(self.circulation, flask.request.library)
        # Don't cache these OPDS entries - they should update immediately
        # in the admin interface when an admin makes a change.
        return entry_response(
            AcquisitionFeed.single_entry(self._db, work, annotator),
            cache_for=0,
        )
Пример #8
0
    def details(self, identifier_type, identifier):
        """Return an OPDS entry with detailed information for admins.

        This includes relevant links for editing the book.

        :return: An OPDSEntryResponse
        """
        self.require_librarian(flask.request.library)

        work = self.load_work(flask.request.library, identifier_type,
                              identifier)
        if isinstance(work, ProblemDetail):
            return work

        annotator = AdminAnnotator(self.circulation, flask.request.library)

        # single_entry returns an OPDSEntryResponse that will not be
        # cached, which is perfect. We want the admin interface
        # to update immediately when an admin makes a change.
        return AcquisitionFeed.single_entry(self._db, work, annotator)