当前位置: 首页>>代码示例>>Python>>正文


Python http_client.FORBIDDEN属性代码示例

本文整理汇总了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 
开发者ID:StackStorm,项目名称:st2,代码行数:26,代码来源:test_inquiries.py

示例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] 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:27,代码来源:restclient.py

示例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" 
开发者ID:suds-community,项目名称:suds,代码行数:23,代码来源:test_reply_handling.py

示例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) 
开发者ID:googlecolab,项目名称:colabtools,代码行数:6,代码来源:test_files_handler.py

示例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) 
开发者ID:googlecolab,项目名称:colabtools,代码行数:16,代码来源:test_files_handler.py

示例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) 
开发者ID:openstack,项目名称:masakari,代码行数:8,代码来源:test_extensions.py

示例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) 
开发者ID:openstack,项目名称:masakari,代码行数:11,代码来源:test_wsgi.py

示例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) 
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_kvps.py

示例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) 
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_kvps.py

示例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"') 
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_auth_api_keys.py

示例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"') 
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_actions.py

示例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 
开发者ID:google,项目名称:apitools,代码行数:29,代码来源:transfer.py

示例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', '/') 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:11,代码来源:restclient_test.py

示例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', '/') 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:9,代码来源:restclient_test.py

示例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 
开发者ID:egnyte,项目名称:python-egnyte,代码行数:17,代码来源:exc.py


注:本文中的six.moves.http_client.FORBIDDEN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。