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


Python Request._process_response_callbacks方法代码示例

本文整理汇总了Python中pyramid.request.Request._process_response_callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python Request._process_response_callbacks方法的具体用法?Python Request._process_response_callbacks怎么用?Python Request._process_response_callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.request.Request的用法示例。


在下文中一共展示了Request._process_response_callbacks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _request

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import _process_response_callbacks [as 别名]
    def _request(self, headers=None):
        if headers is None:
            request = Request({})
        else:
            request = Request({}, headers=headers)

        request.registry = self.config.registry
        event = NewRequest(request)
        add_compress_response_callback(event)

        response = request.response
        request._process_response_callbacks(response)
        return response
开发者ID:ablanco,项目名称:yith-library-server,代码行数:15,代码来源:test_compression.py

示例2: test_create

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import _process_response_callbacks [as 别名]
    def test_create(self):
        from papyrus.protocol import Protocol
        from pyramid.request import Request
        from pyramid.response import Response

        engine = self._get_engine()
        Session = self._get_session(engine)
        MappedClass = self._get_mapped_class()

        class MockSession(object):
            def add(self, o):
                Session.add(o)
            def flush(self):
                pass

        # a before_update callback
        def before_create(request, feature, obj):
            if not hasattr(request, '_log'):
                request._log = []
            request._log.append(dict(feature=feature, obj=obj))

        proto = Protocol(MockSession, MappedClass, "geom",
                         before_create=before_create)

        # we need an actual Request object here, for body to do its job
        request = Request({})
        request.method = 'POST'
        request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
        proto.create(request)
        self.assertEqual(len(request.response_callbacks), 1)
        self.assertEqual(len(Session.new), 2)
        for obj in Session.new:
            self.assertEqual(obj.text, 'foo')
            self.assertEqual(obj.geom.shape.x, 45)
            self.assertEqual(obj.geom.shape.y, 5)
        Session.rollback()

        # test before_create
        self.assertTrue(hasattr(request, '_log'))
        self.assertEqual(len(request._log), 2)
        self.assertEqual(request._log[0]['feature'].properties['text'], 'foo')
        self.assertEqual(request._log[0]['obj'], None)
        self.assertEqual(request._log[1]['feature'].properties['text'], 'foo')
        self.assertEqual(request._log[1]['obj'], None)

        # test response status
        response = Response(status_int=400)
        request._process_response_callbacks(response)
        self.assertEqual(response.status_int, 201)
开发者ID:sbrunner,项目名称:papyrus,代码行数:51,代码来源:test_protocol.py

示例3: test_update

# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import _process_response_callbacks [as 别名]
    def test_update(self):
        from papyrus.protocol import Protocol
        from geojson import Feature
        from pyramid.request import Request
        from pyramid.response import Response
        from geoalchemy import WKBSpatialElement

        MappedClass = self._get_mapped_class()

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {'a': MappedClass(Feature(id='a'))}
            def flush(self):
                pass

        # a before_update callback
        def before_update(request, feature, obj):
            request._log = dict(feature=feature, obj=obj)

        proto = Protocol(MockSession, MappedClass, "geom",
                         before_update=before_update)

        # we need an actual Request object here, for body to do its job
        request = Request({})
        request.method = 'PUT'
        request.body = '{"type": "Feature", "id": "a", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}'

        obj = proto.update(request, "a")

        self.assertEqual(len(request.response_callbacks), 1)
        self.assertTrue(isinstance(obj, MappedClass))
        self.assertTrue(isinstance(obj.geom, WKBSpatialElement))
        self.assertEqual(obj.text, "foo")

        # test before_update
        self.assertTrue(hasattr(request, '_log'))
        self.assertEqual(request._log["feature"].id, 'a')
        self.assertEqual(request._log["feature"].properties['text'], 'foo')
        self.assertTrue(isinstance(request._log["obj"], MappedClass))

        # test response status
        response = Response(status_int=400)
        request._process_response_callbacks(response)
        self.assertEqual(response.status_int, 201)
开发者ID:sbrunner,项目名称:papyrus,代码行数:47,代码来源:test_protocol.py


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