def test_items_that_need_coverage(self):
        source = DataSource.lookup(self._db, DataSource.METADATA_WRANGLER)
        other_source = DataSource.lookup(self._db, DataSource.OVERDRIVE)
        # An item that hasn't been covered by the provider yet
        cr = self._coverage_record(self._edition(), other_source)
        # An item that has been covered by the reaper operation already
        reaper_cr = self._coverage_record(
            self._edition(), source, operation=CoverageRecord.REAP_OPERATION
        )
        # An item that has been covered by the reaper operation, but has
        # had its license repurchased.
        relicensed, relicensed_lp = self._edition(with_license_pool=True)
        self._coverage_record(
            relicensed, source, operation=CoverageRecord.REAP_OPERATION
        )
        relicensed_lp.update_availability(1, 0, 0, 0)

        with temp_config() as config:
            config[Configuration.INTEGRATIONS][Configuration.METADATA_WRANGLER_INTEGRATION] = {
                Configuration.URL : "http://url.gov"
            }
            provider = MetadataWranglerCoverageProvider(self._db)
        items = provider.items_that_need_coverage.all()
        # Provider ignores anything that has been reaped and doesn't have
        # licenses.
        assert reaper_cr.identifier not in items
        # But it picks up anything that hasn't been covered at all and anything
        # that's been licensed anew even if its already been reaped.
        eq_(2, len(items))
        assert relicensed_lp.identifier in items
        assert cr.identifier in items
        # The Wrangler Reaper coverage record is removed from the db
        # when it's committed.
        self._db.commit()
        eq_([], relicensed_lp.identifier.coverage_records)
 def setup(self):
     super(TestMetadataWranglerCollectionReaper, self).setup()
     self.source = DataSource.lookup(self._db, DataSource.METADATA_WRANGLER)
     with temp_config() as config:
         config[Configuration.INTEGRATIONS][Configuration.METADATA_WRANGLER_INTEGRATION] = {
             Configuration.URL : "http://url.gov"
         }
         self.reaper = MetadataWranglerCollectionReaper(self._db)
Пример #3
0
 def setup(self):
     super(TestNoveListAPI, self).setup()
     with temp_config() as config:
         config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
             Configuration.NOVELIST_PROFILE : "library",
             Configuration.NOVELIST_PASSWORD : "******"
         }
         self.novelist = NoveListAPI.from_config(self._db)
Пример #4
0
 def setup(self):
     super(TestNoveListAPI, self).setup()
     with temp_config() as config:
         config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
             Configuration.NOVELIST_PROFILE: "library",
             Configuration.NOVELIST_PASSWORD: "******"
         }
         self.novelist = NoveListAPI.from_config(self._db)
Пример #5
0
 def setup(self):
     super(TestMetadataWranglerCollectionReaper, self).setup()
     self.source = DataSource.lookup(self._db, DataSource.METADATA_WRANGLER)
     with temp_config() as config:
         config[Configuration.INTEGRATIONS][
             Configuration.METADATA_WRANGLER_INTEGRATION] = {
                 Configuration.URL: "http://url.gov"
             }
         self.reaper = MetadataWranglerCollectionReaper(self._db)
Пример #6
0
 def create_provider(self, **kwargs):
     with temp_config() as config:
         config[Configuration.INTEGRATIONS][
             Configuration.METADATA_WRANGLER_INTEGRATION] = {
                 Configuration.URL: "http://url.gov"
             }
         lookup = MockSimplifiedOPDSLookup.from_config()
         return MetadataWranglerCoverageProvider(self._db,
                                                 lookup=lookup,
                                                 **kwargs)
Пример #7
0
    def setup(self):
        super(TestNoveListCoverageProvider, self).setup()
        with temp_config() as config:
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE: "library",
                Configuration.NOVELIST_PASSWORD: "******"
            }
            self.novelist = NoveListCoverageProvider(self._db)
        self.novelist.api = MockNoveListAPI()

        self.metadata = Metadata(data_source=self.novelist.source,
                                 primary_identifier=self._identifier(
                                     identifier_type=Identifier.NOVELIST_ID),
                                 title=u"The Great American Novel")
Пример #8
0
    def setup(self):
        super(TestNoveListCoverageProvider, self).setup()
        with temp_config() as config:
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE : "library",
                Configuration.NOVELIST_PASSWORD : "******"
            }
            self.novelist = NoveListCoverageProvider(self._db)
        self.novelist.api = MockNoveListAPI()

        self.metadata = Metadata(
            data_source = self.novelist.source,
            primary_identifier=self._identifier(
                identifier_type=Identifier.NOVELIST_ID
            ),
            title=u"The Great American Novel"
        )
Пример #9
0
    def test_from_config(self):
        """Confirms that NoveListAPI can be built from config successfully"""

        with temp_config() as config:
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE: "library",
                Configuration.NOVELIST_PASSWORD: "******"
            }
            novelist = NoveListAPI.from_config(self._db)
            eq_(True, isinstance(novelist, NoveListAPI))
            eq_("library", novelist.profile)
            eq_("yep", novelist.password)

            # Without either configuration value, an error is raised.
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE: "library"
            }
            assert_raises(ValueError, NoveListAPI.from_config, self._db)
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PASSWORD: "******"
            }
            assert_raises(ValueError, NoveListAPI.from_config, self._db)
Пример #10
0
    def test_from_config(self):
        """Confirms that NoveListAPI can be built from config successfully"""

        with temp_config() as config:
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE : "library",
                Configuration.NOVELIST_PASSWORD : "******"
            }
            novelist = NoveListAPI.from_config(self._db)
            eq_(True, isinstance(novelist, NoveListAPI))
            eq_("library", novelist.profile)
            eq_("yep", novelist.password)

            # Without either configuration value, an error is raised.
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PROFILE : "library"
            }
            assert_raises(ValueError, NoveListAPI.from_config, self._db)
            config['integrations'][Configuration.NOVELIST_INTEGRATION] = {
                Configuration.NOVELIST_PASSWORD : "******"
            }
            assert_raises(ValueError, NoveListAPI.from_config, self._db)
Пример #11
0
    def test_process_availability(self):
        with temp_config() as config:
            config[Configuration.INTEGRATIONS]['OneClick'] = {
                'library_id': 'library_id_123',
                'username': '******',
                'password': '******',
                'remote_stage': 'qa',
                'base_url': 'www.oneclickapi.test',
                'basic_token': 'abcdef123hijklm',
                "ebook_loan_length": '21',
                "eaudio_loan_length": '21'
            }
            monitor = OneClickCirculationMonitor(self._db)
            monitor.api = MockOneClickAPI(self._db)

        # Create a LicensePool that needs updating.
        edition_ebook, pool_ebook = self._edition(
            identifier_type=Identifier.ONECLICK_ID,
            data_source_name=DataSource.ONECLICK,
            with_license_pool=True)
        pool_ebook.licenses_owned = 3
        pool_ebook.licenses_available = 2
        pool_ebook.patrons_in_hold_queue = 1
        eq_(None, pool_ebook.last_checked)

        # Prepare availability information.
        datastr, datadict = self.api.get_data(
            "response_availability_single_ebook.json")

        # Modify the data so that it appears to be talking about the
        # book we just created.
        new_identifier = pool_ebook.identifier.identifier.encode("ascii")
        datastr = datastr.replace("9781781107041", new_identifier)
        monitor.api.queue_response(status_code=200, content=datastr)

        item_count = monitor.process_availability()
        eq_(1, item_count)
        pool_ebook.licenses_available = 0
Пример #12
0
 def ceq(self, expect, url, cdns):
     cdns = cdns or {}
     with temp_config() as config:
         config[Configuration.INTEGRATIONS][ExternalIntegration.CDN] = cdns
         config[Configuration.CDNS_LOADED_FROM_DATABASE] = True
         assert expect == cdnify(url)
Пример #13
0
 def create_provider(self, **kwargs):
     with temp_config() as config:
         config[Configuration.INTEGRATIONS][Configuration.METADATA_WRANGLER_INTEGRATION] = {
             Configuration.URL : "http://url.gov"
         }
         return MetadataWranglerCoverageProvider(self._db, **kwargs)