當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。