def test_single_entry_no_active_license_pool(self): work = self._work(with_open_access_download=True) pool = work.license_pools[0] # Create an <entry> tag for this work and its LicensePool. feed1 = AcquisitionFeed.single_entry(self._db, work, self.annotator, pool) # If we don't pass in the license pool, it makes a guess to # figure out which license pool we're talking about. feed2 = AcquisitionFeed.single_entry(self._db, work, self.annotator, None) # Both entries are identical. eq_(etree.tostring(feed1), etree.tostring(feed2))
def single_hold_feed(cls, circulation, hold, test_mode=False): db = Session.object_session(hold) work = hold.license_pool.work or hold.license_pool.edition.work annotator = cls(circulation, None, active_loans_by_work={}, active_holds_by_work={work:hold}, test_mode=test_mode) return AcquisitionFeed.single_entry(db, work, annotator)
def single_fulfillment_feed(cls, circulation, loan, fulfillment, test_mode=False): db = Session.object_session(loan) work = loan.license_pool.work or loan.license_pool.presentation_edition.work annotator = cls(circulation, None, loan.patron.library, active_loans_by_work={}, active_holds_by_work={}, active_fulfillments_by_work={work: fulfillment}, test_mode=test_mode) identifier = loan.license_pool.identifier url = annotator.url_for( 'loan_or_hold_detail', identifier_type=identifier.type, identifier=identifier.identifier, library_short_name=loan.patron.library.short_name, _external=True) if not work: return AcquisitionFeed(db, "Active loan for unknown work", url, [], annotator) return AcquisitionFeed.single_entry(db, work, annotator)
def single_hold_feed(cls, circulation, hold, test_mode=False): db = Session.object_session(hold) work = hold.license_pool.work or hold.license_pool.presentation_edition.work annotator = cls(circulation, None, hold.patron.library, active_loans_by_work={}, active_holds_by_work={work:hold}, test_mode=test_mode) return AcquisitionFeed.single_entry(db, work, annotator)
def test_single_entry_no_active_license_pool(self): work = self._work(with_open_access_download=True) pool = work.license_pools[0] # Create an <entry> tag for this work and its LicensePool. feed1 = AcquisitionFeed.single_entry( self._db, work, self.annotator, pool ) # If we don't pass in the license pool, it makes a guess to # figure out which license pool we're talking about. feed2 = AcquisitionFeed.single_entry( self._db, work, self.annotator, None ) # Both entries are identical. eq_(etree.tostring(feed1), etree.tostring(feed2))
def test_permalink(self): with self.app.test_request_context("/"): response = self.manager.work_controller.permalink(self.datasource, self.identifier) annotator = CirculationManagerAnnotator(None, None) expect = etree.tostring( AcquisitionFeed.single_entry( self._db, self.english_1, annotator ) ) eq_(200, response.status_code) eq_(expect, response.data) eq_(OPDSFeed.ENTRY_TYPE, response.headers['Content-Type'])
def single_loan_feed(cls, circulation, loan, test_mode=False): db = Session.object_session(loan) work = loan.license_pool.work or loan.license_pool.edition.work annotator = cls(circulation, None, active_loans_by_work={work:loan}, active_holds_by_work={}, test_mode=test_mode) url = annotator.url_for( 'loan_or_hold_detail', data_source=loan.license_pool.data_source.name, identifier=loan.license_pool.identifier.identifier, _external=True) if not work: return AcquisitionFeed( db, "Active loan for unknown work", url, [], annotator) return AcquisitionFeed.single_entry(db, work, annotator)
def details(self, data_source, identifier_type, identifier): """Return an OPDS entry with detailed information for admins. This includes relevant links for editing the book. """ pool = self.load_licensepool(data_source, identifier_type, identifier) if isinstance(pool, ProblemDetail): return pool work = pool.work annotator = AdminAnnotator(self.circulation) return entry_response( AcquisitionFeed.single_entry(self._db, work, annotator) )
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, )
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)