def test_wrapper(self):

    class TestServer(Server):

        @catch_errors_and_unavailability
        def throw_error(self, uri):
            raise ValueError()

        @catch_errors_and_unavailability
        def throw_oauth_error(self, uri):
            raise OAuth2Error()

        @catch_errors_and_unavailability
        def throw_fatal_oauth_error(self, uri):
            raise FatalClientError()
    validator = RequestValidator()
    server = TestServer(validator)
    server.catch_errors = True
    (h, b, s) = server.throw_error('a')
    self.assertIn('server_error', b)
    self.assertEqual(s, 500)
    server.available = False
    (h, b, s) = server.throw_error('a')
    self.assertIn('temporarily_unavailable', b)
    self.assertEqual(s, 503)
    server.available = True
    self.assertRaises(OAuth2Error, server.throw_oauth_error, 'a')
    self.assertRaises(FatalClientError, server.throw_fatal_oauth_error, 'a')
    server.catch_errors = False
    self.assertRaises(OAuth2Error, server.throw_oauth_error, 'a')
    self.assertRaises(FatalClientError, server.throw_fatal_oauth_error, 'a')
def test_wrapper(self):

    class TestServer(Server):

        @catch_errors_and_unavailability
        def throw_error(self, uri):
            raise ValueError()

        @catch_errors_and_unavailability
        def throw_oauth_error(self, uri):
            raise OAuth2Error()

        @catch_errors_and_unavailability
        def throw_fatal_oauth_error(self, uri):
            raise FatalClientError()
    validator = RequestValidator()
    server = TestServer(validator)
    server.catch_errors = True
    (h, b, s) = server.throw_error('a')
    self.assertIn('server_error', b)
    self.assertEqual(s, 500)
    server.available = False
    (h, b, s) = server.throw_error('a')
    self.assertIn('temporarily_unavailable', b)
    self.assertEqual(s, 503)
    server.available = True
    self.assertRaises(OAuth2Error, server.throw_oauth_error, 'a')
    self.assertRaises(FatalClientError, server.throw_fatal_oauth_error, 'a')
    server.catch_errors = False
    self.assertRaises(OAuth2Error, server.throw_oauth_error, 'a')
    self.assertRaises(FatalClientError, server.throw_fatal_oauth_error, 'a')