Example #1
0
    def test_update_existing_licensepool(self):
        data, raw = self.sample_json("overdrive_availability_information.json")

        # Create a LicensePool.
        wr, pool = self._edition(data_source_name=DataSource.OVERDRIVE,
                                 identifier_type=Identifier.OVERDRIVE_ID,
                                 with_license_pool=True)

        # Make it look like the availability information is for the
        # newly created LicensePool.
        raw['id'] = pool.identifier.identifier

        wr.title = "The real title."
        eq_(1, pool.licenses_owned)
        eq_(1, pool.licenses_available)
        eq_(0, pool.licenses_reserved)
        eq_(0, pool.patrons_in_hold_queue)

        api = MockOverdriveAPI(self._db)
        p2, was_new, changed = api.update_licensepool_with_book_info(
            raw, pool, False)
        eq_(False, was_new)
        eq_(True, changed)
        eq_(p2, pool)
        # The title didn't change to that title given in the availability
        # information, because we already set a title for that work.
        eq_("The real title.", wr.title)
        eq_(raw['copiesOwned'], pool.licenses_owned)
        eq_(raw['copiesAvailable'], pool.licenses_available)
        eq_(0, pool.licenses_reserved)
        eq_(raw['numberOfHolds'], pool.patrons_in_hold_queue)
Example #2
0
    def test_update_new_licensepool(self):
        data, raw = self.sample_json("overdrive_availability_information.json")

        # Create an identifier
        identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID)

        # Make it look like the availability information is for the
        # newly created Identifier.
        raw['id'] = identifier.identifier

        api = MockOverdriveAPI(self._db)
        pool, was_new = LicensePool.for_foreign_id(self._db,
                                                   DataSource.OVERDRIVE,
                                                   identifier.type,
                                                   identifier.identifier)

        pool, was_new, changed = api.update_licensepool_with_book_info(
            raw, pool, was_new)
        eq_(True, was_new)
        eq_(True, changed)

        self._db.commit()

        eq_(raw['copiesOwned'], pool.licenses_owned)
        eq_(raw['copiesAvailable'], pool.licenses_available)
        eq_(0, pool.licenses_reserved)
        eq_(raw['numberOfHolds'], pool.patrons_in_hold_queue)
Example #3
0
    def test_update_licensepool_with_holds(self):
        data, raw = self.sample_json(
            "overdrive_availability_information_holds.json")
        identifier = self._identifier(identifier_type=Identifier.OVERDRIVE_ID)
        raw['id'] = identifier.identifier

        api = MockOverdriveAPI(self._db)
        license_pool, is_new = LicensePool.for_foreign_id(
            self._db, DataSource.OVERDRIVE, identifier.type,
            identifier.identifier)
        pool, was_new, changed = api.update_licensepool_with_book_info(
            raw, license_pool, is_new)
        eq_(10, pool.patrons_in_hold_queue)
        eq_(True, changed)