當前位置: 首頁>>代碼示例>>Python>>正文


Python falcon.Response方法代碼示例

本文整理匯總了Python中falcon.Response方法的典型用法代碼示例。如果您正苦於以下問題:Python falcon.Response方法的具體用法?Python falcon.Response怎麽用?Python falcon.Response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在falcon的用法示例。


在下文中一共展示了falcon.Response方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_process_request_user

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_process_request_user(self):
        ''' AuthMiddleware is expected to correctly identify the headers
            added to an authenticated request by keystonemiddleware in a
            PasteDeploy configuration
        '''

        req_env = TestAuthMiddleware.ks_user_env

        project_id = str(uuid.uuid4().hex)
        req_env['HTTP_X_PROJECT_ID'] = project_id
        user_id = str(uuid.uuid4().hex)
        req_env['HTTP_X_USER_ID'] = user_id
        token = str(uuid.uuid4().hex)
        req_env['HTTP_X_AUTH_TOKEN'] = token

        middleware = AuthMiddleware()
        request = DrydockRequest(req_env)
        response = falcon.Response()

        middleware.process_request(request, response)

        assert request.context.authenticated
        assert request.context.user_id == user_id 
開發者ID:airshipit,項目名稱:drydock,代碼行數:25,代碼來源:test_auth_middleware.py

示例2: test_process_request_user_noauth

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_process_request_user_noauth(self):
        ''' AuthMiddleware is expected to correctly identify the headers
            added to an unauthenticated (no token, bad token) request by
            keystonemiddleware in a PasteDeploy configuration
        '''

        req_env = TestAuthMiddleware.ks_user_env

        req_env['HTTP_X_IDENTITY_STATUS'] = 'Invalid'

        middleware = AuthMiddleware()
        request = DrydockRequest(req_env)
        response = falcon.Response()

        middleware.process_request(request, response)

        assert request.context.authenticated is False 
開發者ID:airshipit,項目名稱:drydock,代碼行數:19,代碼來源:test_auth_middleware.py

示例3: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def on_get(self, req, resp, handler=None, **kwargs):
        """Respond on GET HTTP request assuming resource retrieval flow.

        This request handler assumes that GET requests are associated with
        single resource instance retrieval. Thus default flow for such requests
        is:

        * Retrieve single resource instance of prepare its representation by
          calling retrieve method handler.

        Args:
            req (falcon.Request): request object instance.
            resp (falcon.Response): response object instance to be modified
            handler (method): list method handler to be called. Defaults
                to ``self.list``.
            **kwargs: additional keyword arguments retrieved from url template.
        """
        self.handle(
            handler or self.retrieve, req, resp, **kwargs
        ) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:22,代碼來源:mixins.py

示例4: on_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def on_delete(self, req, resp, handler=None, **kwargs):
        """Respond on DELETE HTTP request assuming resource deletion flow.

        This request handler assumes that DELETE requests are associated with
        resource deletion. Thus default flow for such requests is:

        * Delete existing resource instance.
        * Set response status code to ``202 Accepted``.

        Args:
            req (falcon.Request): request object instance.
            resp (falcon.Response): response object instance to be modified
            handler (method): deletion method handler to be called. Defaults
                to ``self.delete``.
            **kwargs: additional keyword arguments retrieved from url template.
        """
        self.handle(
            handler or self.delete, req, resp, **kwargs
        )

        resp.status = falcon.HTTP_ACCEPTED 
開發者ID:swistakm,項目名稱:graceful,代碼行數:23,代碼來源:mixins.py

示例5: on_put

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def on_put(self, req, resp, handler=None, **kwargs):
        """Respond on PUT HTTP request assuming resource update flow.

        This request handler assumes that PUT requests are associated with
        resource update/modification. Thus default flow for such requests is:

        * Modify existing resource instance and prepare its representation by
          calling its update method handler.
        * Set response status code to ``202 Accepted``.

        Args:
            req (falcon.Request): request object instance.
            resp (falcon.Response): response object instance to be modified
            handler (method): update method handler to be called. Defaults
                to ``self.update``.
            **kwargs: additional keyword arguments retrieved from url template.
        """
        self.handle(
            handler or self.update, req, resp, **kwargs
        )
        resp.status = falcon.HTTP_ACCEPTED 
開發者ID:swistakm,項目名稱:graceful,代碼行數:23,代碼來源:mixins.py

示例6: on_patch

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def on_patch(self, req, resp, handler=None, **kwargs):
        """Respond on POST HTTP request assuming resource creation flow.

        This request handler assumes that POST requests are associated with
        resource creation. Thus default flow for such requests is:

        * Create new resource instances and prepare their representation by
          calling its bulk creation method handler.
        * Set response status code to ``201 Created``.

        **Note:** this handler does not set ``Location`` header by default as
        it would be valid only for single resource creation.

        Args:
            req (falcon.Request): request object instance.
            resp (falcon.Response): response object instance to be modified
            handler (method): creation method handler to be called. Defaults
                to ``self.create``.
            **kwargs: additional keyword arguments retrieved from url template.
        """
        self.handle(
            handler or self.create_bulk, req, resp, **kwargs
        )

        resp.status = falcon.HTTP_CREATED 
開發者ID:swistakm,項目名稱:graceful,代碼行數:27,代碼來源:mixins.py

示例7: make_body

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def make_body(self, resp, params, meta, content):
        """Construct response body in ``resp`` object using JSON serialization.

        Args:
            resp (falcon.Response): response object where to include
                serialized body
            params (dict): dictionary of parsed parameters
            meta (dict): dictionary of metadata to be included in 'meta'
                section of response
            content (dict): dictionary of response content (resource
                representation) to be included in 'content' section of response

        Returns:
            None

        """
        response = {
            'meta': meta,
            'content': content
        }
        resp.content_type = 'application/json'
        resp.body = json.dumps(
            response,
            indent=params['indent'] or None if 'indent' in params else None
        ) 
開發者ID:swistakm,項目名稱:graceful,代碼行數:27,代碼來源:base.py

示例8: on_options

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def on_options(self, req, resp, **kwargs):
        """Respond with JSON formatted resource description on OPTIONS request.

        Args:
            req (falcon.Request): Optional request object. Defaults to None.
            resp (falcon.Response): Optional response object. Defaults to None.
            kwargs (dict): Dictionary of values created by falcon from
                resource uri template.

        Returns:
            None


        .. versionchanged:: 0.2.0
           Default ``OPTIONS`` responses include ``Allow`` header with list of
           allowed HTTP methods.
        """
        resp.set_header('Allow', ', '.join(self.allowed_methods()))
        resp.body = json.dumps(self.describe(req, resp))
        resp.content_type = 'application/json' 
開發者ID:swistakm,項目名稱:graceful,代碼行數:22,代碼來源:base.py

示例9: get_user

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def get_user(
        self, identified_with, identifier, req, resp, resource, uri_kwargs
    ):
        """Get user from the storage.

        Args:
            identified_with (str): instance of the authentication middleware
                that provided the ``identifier`` value.
            identifier (str): string that identifies the user (it is specific
                for every authentication middleware implementation).
            req (falcon.Request): the request object.
            resp (falcon.Response): the response object.
            resource (object): the resource object.
            uri_kwargs (dict): keyword arguments from the URI template.

        Returns:
            the deserialized user object. Preferably a ``dict`` but it is
            application-specific.
        """
        raise NotImplementedError  # pragma: nocover 
開發者ID:swistakm,項目名稱:graceful,代碼行數:22,代碼來源:authentication.py

示例10: test_base_resource_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_base_resource_get(req, resp):
    """
    Test that simple resource GET will return 200 OK response with JSON encoded
    body.

    Args:
        req (falcon.Request): request instance object provided by ``req``
           pytest fixture

        resp (falcon.Response): responce instance provided by ``resp`` pytest
           fixture
    """
    resource = TestResource()

    resource.on_get(req, resp)

    assert resp.content_type == "application/json"
    assert resp.body
    assert resp.status == falcon.HTTP_200 
開發者ID:swistakm,項目名稱:graceful,代碼行數:21,代碼來源:test_resources.py

示例11: test_resource_meta

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_resource_meta(req, resp):
    """
    Test if meta output part on resource GET has a desired structure

    Args:
        req (falcon.Request): request instance object provided by ``req``
            pytest fixture
        resp (falcon.Response): responce instance provided by ``resp`` pytest
            fixture
    """
    resource = TestResource()
    resource.on_get(req, resp)

    body = json.loads(resp.body)

    assert 'meta' in body
    assert 'params' in body['meta'] 
開發者ID:swistakm,項目名稱:graceful,代碼行數:19,代碼來源:test_resources.py

示例12: test_required_params

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_required_params(req, resp):
    """
    Test that when params are missing then specific falcon exception is raised
    and thus proper status code will be returned.

    Args:
        req (falcon.Request): request instance object provided by ``req``
            pytest fixture
        resp (falcon.Response): responce instance provided by ``resp`` pytest
            fixture
    """
    class ParametrizedResource(TestResource):
        foo = StringParam(details="required foo!", required=True)

    resource = ParametrizedResource()

    with pytest.raises(errors.HTTPMissingParam):
        resource.on_get(req, resp)

    param_req = copy.copy(req)
    param_req.params['foo'] = 'bar'
    resource.on_get(req, resp)
    assert resp.status == falcon.HTTP_OK 
開發者ID:swistakm,項目名稱:graceful,代碼行數:25,代碼來源:test_resources.py

示例13: test_describe

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_describe(req, resp):
    """
    Test if output of resource.description() has desired form.

    Args:
        req (falcon.Request): request instance object provided by ``req``
            pytest fixture
        resp (falcon.Response): responce instance provided by ``resp`` pytest
            fixture
    """
    # default description keys
    resource = Resource()
    description = resource.describe(req, resp)
    assert 'path' in description
    assert 'name' in description
    assert 'details' in description
    assert 'params' in description
    assert 'methods' in description

    # test extending of description through kwargs
    assert 'foo' not in description
    description = resource.describe(req, resp, foo='bar')
    assert 'foo' in description
    assert description['foo'] == 'bar' 
開發者ID:swistakm,項目名稱:graceful,代碼行數:26,代碼來源:test_resources.py

示例14: test_get_health

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_get_health(mocker, deckhand_orchestrator, drydock_state):
    api = HealthResource(
        state_manager=drydock_state, orchestrator=deckhand_orchestrator)

    # Configure mocked request and response
    req = mocker.MagicMock(spec=falcon.Request)
    resp = mocker.MagicMock(spec=falcon.Response)

    api.on_get(req, resp)

    assert resp.status == falcon.HTTP_204 
開發者ID:airshipit,項目名稱:drydock,代碼行數:13,代碼來源:test_api_health.py

示例15: test_get_versions

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import Response [as 別名]
def test_get_versions(mocker):
    api = VersionsResource()

    # Configure mocked request and response
    req = mocker.MagicMock(spec=falcon.Request)
    resp = mocker.MagicMock(spec=falcon.Response)

    api.on_get(req, resp)

    expected = api.to_json({'v1.0': {'path': '/api/v1.0', 'status': 'stable'}})

    assert resp.body == expected
    assert resp.status == falcon.HTTP_200 
開發者ID:airshipit,項目名稱:drydock,代碼行數:15,代碼來源:test_api_versions.py


注:本文中的falcon.Response方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。