예제 #1
0
    def test_process_item_creates_presentation_ready_work(self):
        # Test the normal workflow where we ask OneClick for data,
        # OneClick provides it, and we create a presentation-ready work.
        
        datastr, datadict = self.api.get_data("response_isbn_found_1.json")
        self.api.queue_response(200, content=datastr)
        
        # Here's the book mentioned in response_isbn_found_1.
        identifier = self._identifier(identifier_type=Identifier.ONECLICK_ID)
        identifier.identifier = '9780307378101'

        # This book has no LicensePool.
        eq_(None, identifier.licensed_through)

        # Run it through the OneClickBibliographicCoverageProvider
        provider = OneClickBibliographicCoverageProvider(
            self._db, oneclick_api=self.api
        )
        result = provider.process_item(identifier)
        eq_(identifier, result)

        # A LicensePool was created. But we do NOT know how many copies of this
        # book are available, only what formats it's available in.
        pool = identifier.licensed_through
        eq_(0, pool.licenses_owned)
        [lpdm] = pool.delivery_mechanisms
        eq_('application/epub+zip (vnd.adobe/adept+xml)', lpdm.delivery_mechanism.name)

        # A Work was created and made presentation ready.
        eq_('Tea Time for the Traditionally Built', pool.work.title)
        eq_(True, pool.work.presentation_ready)
예제 #2
0
    def setup(self):
        super(TestOneClickBibliographicCoverageProvider, self).setup()

        self.provider = OneClickBibliographicCoverageProvider(
            self.collection,
            api_class=MockOneClickAPI,
            api_class_kwargs=dict(base_path=os.path.split(__file__)[0]))
        self.api = self.provider.api
예제 #3
0
class TestOneClickBibliographicCoverageProvider(OneClickTest):
    """Test the code that looks up bibliographic information from OneClick."""
    def setup(self):
        super(TestOneClickBibliographicCoverageProvider, self).setup()

        self.provider = OneClickBibliographicCoverageProvider(
            self.collection,
            api_class=MockOneClickAPI,
            api_class_kwargs=dict(base_path=os.path.split(__file__)[0]))
        self.api = self.provider.api

    def test_script_instantiation(self):
        """Test that RunCoverageProviderScript can instantiate
        the coverage provider.
        """
        script = RunCollectionCoverageProviderScript(
            OneClickBibliographicCoverageProvider,
            self._db,
            api_class=MockOneClickAPI)
        [provider] = script.providers
        assert isinstance(provider, OneClickBibliographicCoverageProvider)
        assert isinstance(provider.api, MockOneClickAPI)
        eq_(self.collection, provider.collection)

    def test_invalid_or_unrecognized_guid(self):
        # A bad or malformed ISBN can't get coverage.

        identifier = self._identifier()
        identifier.identifier = 'ISBNbadbad'

        datastr, datadict = self.api.get_data("response_isbn_notfound_1.json")
        self.api.queue_response(status_code=200, content=datastr)

        failure = self.provider.process_item(identifier)
        assert isinstance(failure, CoverageFailure)
        eq_(True, failure.transient)
        assert failure.exception.startswith('Cannot find OneClick metadata')

    def test_process_item_creates_presentation_ready_work(self):
        # Test the normal workflow where we ask OneClick for data,
        # OneClick provides it, and we create a presentation-ready work.

        datastr, datadict = self.api.get_data("response_isbn_found_1.json")
        self.api.queue_response(200, content=datastr)

        # Here's the book mentioned in response_isbn_found_1.
        identifier = self._identifier(identifier_type=Identifier.ONECLICK_ID)
        identifier.identifier = '9780307378101'

        # This book has no LicensePool.
        eq_([], identifier.licensed_through)

        # Run it through the OneClickBibliographicCoverageProvider
        result = self.provider.process_item(identifier)
        eq_(identifier, result)

        # A LicensePool was created. But we do NOT know how many copies of this
        # book are available, only what formats it's available in.
        [pool] = identifier.licensed_through
        eq_(0, pool.licenses_owned)
        [lpdm] = pool.delivery_mechanisms
        eq_('application/epub+zip (application/vnd.adobe.adept+xml)',
            lpdm.delivery_mechanism.name)

        # A Work was created and made presentation ready.
        eq_('Tea Time for the Traditionally Built', pool.work.title)
        eq_(True, pool.work.presentation_ready)
예제 #4
0
    def setup(self):
        super(TestOneClickBibliographicCoverageProvider, self).setup()

        self.provider = OneClickBibliographicCoverageProvider(
            self._db, oneclick_api=self.api
        )