Пример #1
0
 def test_update_licensepool_error(self):
     # Create an identifier.
     identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID)
     ignore, availability = self.sample_json(
         "overdrive_availability_information.json")
     api = MockOverdriveAPI(self._db)
     api.queue_response(500, content="An error occured.")
     book = dict(id=identifier.identifier, availability_link=self._url)
     pool, was_new, changed = api.update_licensepool(book)
     eq_(None, pool)
Пример #2
0
    def test_update_licensepool_provides_bibliographic_coverage(self):
        # Create an identifier.
        identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID)

        # Prepare bibliographic and availability information
        # for this identifier.
        ignore, availability = self.sample_json(
            "overdrive_availability_information.json")
        ignore, bibliographic = self.sample_json(
            "bibliographic_information.json")

        # To avoid a mismatch, make it look like the information is
        # for the newly created Identifier.
        availability['id'] = identifier.identifier
        bibliographic['id'] = identifier.identifier

        api = MockOverdriveAPI(self._db)
        api.queue_response(200, content=availability)
        api.queue_response(200, content=bibliographic)

        # Now we're ready. When we call update_licensepool, the
        # OverdriveAPI will retrieve the availability information,
        # then the bibliographic information. It will then trigger the
        # OverdriveBibliographicCoverageProvider, which will
        # create an Edition and a presentation-ready Work.
        pool, was_new, changed = api.update_licensepool(identifier.identifier)
        eq_(True, was_new)
        eq_(availability['copiesOwned'], pool.licenses_owned)

        edition = pool.presentation_edition
        eq_("Ancillary Justice", edition.title)

        eq_(True, pool.work.presentation_ready)
        assert pool.work.cover_thumbnail_url.startswith(
            'http://images.contentreserve.com/')

        # The book has been run through the bibliographic coverage
        # provider.
        coverage = [
            x for x in identifier.coverage_records if x.operation is None
            and x.data_source.name == DataSource.OVERDRIVE
        ]
        eq_(1, len(coverage))