コード例 #1
0
 def test_unknown_error_becomes_remote_initiated_server_error(self):
     """Simulate the message we get when ¯\_(ツ)_/¯."""
     msg = self.sample_data("error_unknown.xml")
     error = ErrorParser().process_all(msg)
     assert isinstance(error, RemoteInitiatedServerError)
     eq_(BibliothecaAPI.SERVICE_NAME, error.service_name)
     eq_("Unknown error", error.message)
コード例 #2
0
    def test_exception(self):
        parser = ErrorParser()

        error = parser.process_all(self.NOT_LOANABLE)
        assert isinstance(error, NoAvailableCopies)

        error = parser.process_all(self.ALREADY_ON_LOAN)
        assert isinstance(error, AlreadyCheckedOut)

        error = parser.process_all(self.ALREADY_ON_HOLD)
        assert isinstance(error, AlreadyOnHold)

        error = parser.process_all(self.TOO_MANY_LOANS)
        assert isinstance(error, PatronLoanLimitReached)

        error = parser.process_all(self.TRIED_TO_CANCEL_NONEXISTENT_HOLD)
        assert isinstance(error, NotOnHold)

        error = parser.process_all(self.TRIED_TO_RETURN_UNLOANED_BOOK)
        assert isinstance(error, NotCheckedOut)

        error = parser.process_all(self.TRIED_TO_HOLD_LOANABLE_BOOK)
        assert isinstance(error, CurrentlyAvailable)

        # This is such a weird case we don't have a special
        # exception for it.
        error = parser.process_all(self.TRIED_TO_HOLD_BOOK_ON_LOAN)
        assert isinstance(error, CannotHold)
コード例 #3
0
 def test_malformed_error_message_becomes_remote_initiated_server_error(
         self):
     msg = """<weird>This error does not follow the standard set out by 3M.</weird>"""
     error = ErrorParser().process_all(msg)
     assert isinstance(error, RemoteInitiatedServerError)
     eq_(BibliothecaAPI.SERVICE_NAME, error.service_name)
     eq_("Unknown error", error.message)
コード例 #4
0
 def test_exceeded_limit(self):
     """The normal case--we get a helpful error message which we turn into
     an appropriate circulation exception.
     """
     msg = self.sample_data("error_exceeded_limit.xml")
     error = ErrorParser().process_all(msg)
     assert isinstance(error, PatronLoanLimitReached)
     eq_(u'Patron cannot loan more than 12 documents', error.message)
コード例 #5
0
 def test_remote_authentication_failed_becomes_remote_initiated_server_error(self):
     """Simulate the message we get when the error message is
     'Authentication failed' but our authentication information is
     set up correctly.
     """
     msg=self.sample_data("error_authentication_failed.xml")
     error = ErrorParser().process_all(msg)
     assert isinstance(error, RemoteInitiatedServerError)
     eq_(BibliothecaAPI.SERVICE_NAME, error.service_name)
     eq_("Authentication failed", error.message)
コード例 #6
0
 def test_internal_server_error_beomces_remote_initiated_server_error(self):
     """Simulate the message we get when the server goes down."""
     msg = "The server has encountered an error"
     error = ErrorParser().process_all(msg)
     assert isinstance(error, RemoteInitiatedServerError)
     eq_(BibliothecaAPI.SERVICE_NAME, error.service_name)
     eq_(502, error.status_code)
     eq_(msg, error.message)
     doc = error.as_problem_detail_document()
     eq_(502, doc.status_code)
     eq_("Integration error communicating with 3M", doc.detail)
コード例 #7
0
    def test_wrong_status(self):
        msg = self.sample_data("error_no_licenses.xml")
        error = ErrorParser().process_all(msg)
        assert isinstance(error, NoLicenses)
        eq_(
            u'the patron document status was CAN_WISH and not one of CAN_LOAN,RESERVATION',
            error.message)

        problem = error.as_problem_detail_document()
        eq_("The library currently has no licenses for this book.",
            problem.detail)
        eq_(404, problem.status_code)
コード例 #8
0
 def test_blank_error_message_becomes_remote_initiated_server_error(self):
     msg = """<Error xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Message/></Error>"""
     error = ErrorParser().process_all(msg)
     assert isinstance(error, RemoteInitiatedServerError)
     eq_(BibliothecaAPI.SERVICE_NAME, error.service_name)
     eq_("Unknown error", error.message)
コード例 #9
0
 def test_exceeded_hold_limit(self):
     msg = self.sample_data("error_exceeded_hold_limit.xml")
     error = ErrorParser().process_all(msg)
     assert isinstance(error, PatronHoldLimitReached)
     eq_(u'Patron cannot have more than 15 holds', error.message)