Exemple #1
0
 def test_availability_exception(self):
     api = MockAxis360API(self._db)
     api.queue_response(500)
     assert_raises_regexp(
         RemoteIntegrationException,
         "Bad response from http://axis.test/availability/v2: Got status code 500 from external server, cannot continue.",
         api.availability)
Exemple #2
0
    def test_transient_failure_if_requested_book_not_mentioned(self):
        """Test an unrealistic case where we ask Axis 360 about one book and
        it tells us about a totally different book.
        """
        api = MockAxis360API(self._db)

        # We're going to ask about abcdef
        identifier = self._identifier(identifier_type=Identifier.AXIS_360_ID)
        identifier.identifier = 'abcdef'

        # But we're going to get told about 0003642860.
        data = self.get_data("single_item.xml")
        api.queue_response(200, content=data)

        # Run abcdef through the Axis360BibliographicCoverageProvider.
        provider = Axis360BibliographicCoverageProvider(self._db,
                                                        axis_360_api=api)
        [result] = provider.process_batch([identifier])

        # Coverage failed for the book we asked about.
        assert isinstance(result, CoverageFailure)
        eq_(identifier, result.obj)
        eq_("Book not in collection", result.exception)

        # And nothing major was done about the book we were told
        # about. We created an Identifier record for its identifier,
        # but no LicensePool or Edition.
        wrong_identifier = Identifier.for_foreign_id(self._db,
                                                     Identifier.AXIS_360_ID,
                                                     "0003642860")
        eq_(None, identifier.licensed_through)
        eq_([], identifier.primarily_identifies)
Exemple #3
0
    def test_process_item_creates_presentation_ready_work(self):
        """Test the normal workflow where we ask Axis for data,
        Axis provides it, and we create a presentation-ready work.
        """
        api = MockAxis360API(self._db)
        data = self.get_data("single_item.xml")
        api.queue_response(200, content=data)

        # Here's the book mentioned in single_item.xml.
        identifier = self._identifier(identifier_type=Identifier.AXIS_360_ID)
        identifier.identifier = '0003642860'

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

        # Run it through the Axis360BibliographicCoverageProvider
        provider = Axis360BibliographicCoverageProvider(self._db,
                                                        axis_360_api=api)
        [result] = provider.process_batch([identifier])
        eq_(identifier, result)

        # A LicensePool was created. We know both how many copies of this
        # book are available, and what formats it's available in.
        pool = identifier.licensed_through
        eq_(9, 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_('Faith of My Fathers : A Family Memoir', pool.work.title)
        eq_(True, pool.work.presentation_ready)
Exemple #4
0
 def test_refresh_bearer_token_error(self):
     """Raise an exception if we don't get a 200 status code when
     refreshing the bearer token.
     """
     api = MockAxis360API(self._db, self.collection, with_token=False)
     api.queue_response(412)
     assert_raises_regexp(
         RemoteIntegrationException, "Bad response from http://axis.test/accesstoken: Got status code 412 from external server, but can only continue on: 200.", 
         api.refresh_bearer_token
     )
Exemple #5
0
 def test_refresh_bearer_token_after_401(self):
     """If we get a 401, we will fetch a new bearer token and try the
     request again.
     """
     api = MockAxis360API(self._db)
     api.queue_response(401)
     api.queue_response(200, content=json.dumps(dict(access_token="foo")))
     api.queue_response(200, content="The data")
     response = api.request("http://url/")
     eq_("The data", response.content)
Exemple #6
0
 def test_script_instantiation(self):
     """Test that RunCoverageProviderScript can instantiate
     the coverage provider.
     """
     api = MockAxis360API(self._db)
     script = RunCoverageProviderScript(
         Axis360BibliographicCoverageProvider,
         self._db, [],
         axis_360_api=api)
     assert isinstance(script.provider,
                       Axis360BibliographicCoverageProvider)
     eq_(script.provider.api, api)
Exemple #7
0
    def test_exception_after_401_with_fresh_token(self):
        """If we get a 401 immediately after refreshing the token, we will
        raise an exception.
        """
        api = MockAxis360API(self._db)
        api.queue_response(401)
        api.queue_response(200, content=json.dumps(dict(access_token="foo")))
        api.queue_response(401)

        api.queue_response(301)

        assert_raises_regexp(
            RemoteIntegrationException,
            ".*Got status code 401 from external server, cannot continue.",
            api.request, "http://url/")

        # The fourth request never got made.
        eq_([301], [x.status_code for x in api.responses])
Exemple #8
0
 def setup(self):
     super(AxisTestWithAPI, self).setup()
     self.api = MockAxis360API(self._db, self.collection)
Exemple #9
0
 def setup(self):
     super(AxisTest, self).setup()
     self.collection = MockAxis360API.mock_collection(self._db)