本文整理汇总了Python中six.moves.http_client.FORBIDDEN属性的典型用法代码示例。如果您正苦于以下问题:Python http_client.FORBIDDEN属性的具体用法?Python http_client.FORBIDDEN怎么用?Python http_client.FORBIDDEN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类six.moves.http_client
的用法示例。
在下文中一共展示了http_client.FORBIDDEN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_respond_restrict_users
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_respond_restrict_users(self):
"""Test that Inquiries can reject responses from users not in a list
"""
# Default user for tests is "stanley", which is not in the 'users' list
# Should be rejected
post_resp = self._do_create_inquiry(INQUIRY_2, RESULT_2)
inquiry_id = self._get_inquiry_id(post_resp)
response = {"continue": True}
put_resp = self._do_respond(inquiry_id, response, expect_errors=True)
self.assertEqual(put_resp.status_int, http_client.FORBIDDEN)
self.assertIn('does not have permission to respond', put_resp.json['faultstring'])
# Responding as a use in the list should be accepted
old_user = cfg.CONF.system_user.user
cfg.CONF.system_user.user = "foo"
post_resp = self._do_create_inquiry(INQUIRY_2, RESULT_2)
inquiry_id = self._get_inquiry_id(post_resp)
response = {"continue": True}
put_resp = self._do_respond(inquiry_id, response)
self.assertEqual(response, put_resp.json.get("response"))
# Clean up
cfg.CONF.system_user.user = old_user
示例2: _handle_error
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def _handle_error(url, response):
"""Handle response status codes."""
handlers = {
http_client.NOT_FOUND: NotFoundError(
'Resource not found: {}'.format(url)
),
# XXX: Correct code is CONFLICT. Support invalid FOUND during
# migration.
http_client.FOUND: AlreadyExistsError(
'Resource already exists: {}'.format(url)
),
http_client.CONFLICT: AlreadyExistsError(
'Resource already exists: {}'.format(url)
),
http_client.TOO_MANY_REQUESTS: TooManyRequestsError(response),
http_client.FAILED_DEPENDENCY: ValidationError(response),
# XXX: Correct code is FORBIDDEN. Support invalid UNAUTHORIZED during
# migration.
http_client.UNAUTHORIZED: NotAuthorizedError(response),
http_client.FORBIDDEN: NotAuthorizedError(response),
http_client.BAD_REQUEST: BadRequestError(response),
}
if response.status_code in handlers:
raise handlers[response.status_code]
示例3: test_empty_reply
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_empty_reply():
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False)
def f(status=None, description=None):
inject = dict(reply=suds.byte_str(), status=status,
description=description)
return client.service.f(__inject=inject)
status, reason = f()
assert status == http_client.OK
assert reason is None
status, reason = f(http_client.OK)
assert status == http_client.OK
assert reason is None
status, reason = f(http_client.INTERNAL_SERVER_ERROR)
assert status == http_client.INTERNAL_SERVER_ERROR
assert reason == "injected reply"
status, reason = f(http_client.FORBIDDEN)
assert status == http_client.FORBIDDEN
assert reason == "injected reply"
status, reason = f(http_client.FORBIDDEN, "kwack")
assert status == http_client.FORBIDDEN
assert reason == "kwack"
示例4: testExistingDirectory
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def testExistingDirectory(self):
os.makedirs(os.path.join(self.temp_dir, 'some/existing/dir'))
response = self.fetch('/files/some/existing/dir')
self.assertEqual(http_client.FORBIDDEN, response.code)
示例5: testDoesNotAllowRequestsOutsideOfRootDir
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def testDoesNotAllowRequestsOutsideOfRootDir(self):
# Based on existing tests:
# https://github.com/jupyter/notebook/blob/f5fa0c180e92d35b4cbfa1cc20b41e9d1d9dfabe/notebook/services/contents/tests/test_manager.py#L173
with open(os.path.join(self.temp_dir, '..', 'foo'), 'w') as f:
f.write('foo')
with open(os.path.join(self.temp_dir, '..', 'bar'), 'w') as f:
f.write('bar')
response = self.fetch('/files/../foo')
self.assertEqual(http_client.FORBIDDEN, response.code)
response = self.fetch('/files/foo/../../../bar')
self.assertEqual(http_client.FORBIDDEN, response.code)
response = self.fetch('/files/foo/../../bar')
self.assertEqual(http_client.FORBIDDEN, response.code)
示例6: test_extensions_expected_error_from_list
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_extensions_expected_error_from_list(self):
@extensions.expected_errors((http.NOT_FOUND, http.FORBIDDEN))
def fake_func():
raise webob.exc.HTTPNotFound()
self.assertRaises(webob.exc.HTTPNotFound, fake_func)
示例7: test_resource_not_authorized
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_resource_not_authorized(self):
class Controller(object):
def index(self, req):
raise exception.Forbidden()
req = webob.Request.blank('/tests')
app = fakes.TestRouter(Controller())
response = req.get_response(app)
self.assertEqual(response.status_int, http.FORBIDDEN)
示例8: test_get_all_user_query_param_can_only_be_used_with_rbac
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_get_all_user_query_param_can_only_be_used_with_rbac(self):
resp = self.app.get('/v1/keys?user=foousera', expect_errors=True)
expected_error = '"user" attribute can only be provided by admins when RBAC is enabled'
self.assertEqual(resp.status_int, http_client.FORBIDDEN)
self.assertEqual(resp.json['faultstring'], expected_error)
示例9: test_get_one_user_query_param_can_only_be_used_with_rbac
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_get_one_user_query_param_can_only_be_used_with_rbac(self):
resp = self.app.get('/v1/keys/keystone_endpoint?user=foousera', expect_errors=True)
expected_error = '"user" attribute can only be provided by admins when RBAC is enabled'
self.assertEqual(resp.status_int, http_client.FORBIDDEN)
self.assertEqual(resp.json['faultstring'], expected_error)
示例10: test_get_all_invalid_limit_too_large_none_admin
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_get_all_invalid_limit_too_large_none_admin(self):
# limit > max_page_size, but user is not admin
resp = self.app.get('/v1/apikeys?offset=2&limit=1000', expect_errors=True)
self.assertEqual(resp.status_int, http_client.FORBIDDEN)
self.assertEqual(resp.json['faultstring'],
'Limit "1000" specified, maximum value is "100"')
示例11: test_get_all_invalid_limit_too_large_none_admin
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_get_all_invalid_limit_too_large_none_admin(self):
# limit > max_page_size, but user is not admin
resp = self.app.get('/v1/actions?limit=1000', expect_errors=True)
self.assertEqual(resp.status_int, http_client.FORBIDDEN)
self.assertEqual(resp.json['faultstring'], 'Limit "1000" specified, maximum value is'
' "100"')
示例12: __ProcessResponse
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def __ProcessResponse(self, response):
"""Process response (by updating self and writing to self.stream)."""
if response.status_code not in self._ACCEPTABLE_STATUSES:
# We distinguish errors that mean we made a mistake in setting
# up the transfer versus something we should attempt again.
if response.status_code in (http_client.FORBIDDEN,
http_client.NOT_FOUND):
raise exceptions.HttpError.FromResponse(response)
else:
raise exceptions.TransferRetryError(response.content)
if response.status_code in (http_client.OK,
http_client.PARTIAL_CONTENT):
try:
self.stream.write(six.ensure_binary(response.content))
except TypeError:
self.stream.write(six.ensure_text(response.content))
self.__progress += response.length
if response.info and 'content-encoding' in response.info:
# TODO(craigcitro): Handle the case where this changes over a
# download.
self.__encoding = response.info['content-encoding']
elif response.status_code == http_client.NO_CONTENT:
# It's important to write something to the stream for the case
# of a 0-byte download to a file, as otherwise python won't
# create the file.
self.stream.write('')
return response
示例13: test_get_401
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_get_401(self, resp_mock):
"""Test treadmill.restclient.get UNAUTHORIZED (401)"""
# XXX: Correct code in FORBIDDEN. Support invalid UNAUTHORIZED during
# migration.
resp_mock.return_value.status_code = http_client.UNAUTHORIZED
resp_mock.return_value.json.return_value = {}
with self.assertRaises(restclient.NotAuthorizedError):
restclient.get('http://foo.com', '/')
示例14: test_get_403
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def test_get_403(self, resp_mock):
"""Test treadmill.restclient.get FORBIDDEN (403)"""
resp_mock.return_value.status_code = http_client.FORBIDDEN
resp_mock.return_value.json.return_value = {}
with self.assertRaises(restclient.NotAuthorizedError):
restclient.get('http://foo.com', '/')
示例15: __init__
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import FORBIDDEN [as 别名]
def __init__(self, values=None, ok_statuses=(http_client.OK, ), ignored_errors=None):
super(ErrorMapping, self).__init__({
http_client.BAD_REQUEST: RequestError,
http_client.UNAUTHORIZED: NotAuthorized,
http_client.FORBIDDEN: InsufficientPermissions,
http_client.NOT_FOUND: NotFound,
http_client.CONFLICT: DuplicateRecordExists,
http_client.REQUEST_ENTITY_TOO_LARGE: FileSizeExceedsLimit,
http_client.SEE_OTHER: Redirected,
})
if values:
self.update(values)
if ignored_errors:
self.ignored_errors = recursive_tuple(ignored_errors)
self.ok_statuses = ok_statuses