@patch('requests.get')
    def test_not_available(self, r_get):
        # Response based off Xero documentation; not confirmed by reality.
        r_get.return_value = Mock(
            status_code=503,
            text="The Xero API is currently offline for maintenance"
        )

        credentials = Mock(base_url="")
        xero = Xero(credentials)

        try:
            xero.contacts.all()
            self.fail("Should raise a XeroNotAvailable.")

        except XeroNotAvailable as e:
            # Error messages have been extracted
            self.assertEqual(str(e), "The Xero API is currently offline for maintenance")

            # The response has also been stored
            self.assertEqual(e.response.status_code, 503)
            self.assertEqual(e.response.text, "The Xero API is currently offline for maintenance")
        except Exception as e:
            self.fail("Should raise a XeroNotAvailable, not %s" % e)
If Xero goes down for maintenance, an exception is raised
dataset/ETHPy150Open freakboy3742/pyxero/tests/exceptions.py/ExceptionsTest.test_not_available