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


Python Protocol.update方法代码示例

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


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

示例1: test_update_forbidden

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import update [as 别名]
    def test_update_forbidden(self):
        from papyrus.protocol import Protocol
        from pyramid.testing import DummyRequest

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

        proto = Protocol(Session, MappedClass, "geom", readonly=True)
        # we need an actual Request object here, for body to do its job
        request = DummyRequest({})
        request.method = 'PUT'
        request.body = '{"type": "Feature", "id": 1, "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}'  # NOQA
        response = proto.update(request, 1)
        self.assertTrue(response.headers.get('Allow') == "GET, HEAD")
        self.assertEqual(response.status_int, 405)
开发者ID:gberaudo,项目名称:papyrus,代码行数:18,代码来源:test_protocol.py

示例2: test_update_badrequest

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import update [as 别名]
    def test_update_badrequest(self):
        from papyrus.protocol import Protocol
        from pyramid.testing import DummyRequest

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {'a': {}}

        proto = Protocol(MockSession, self._get_mapped_class(), "geom")

        # we need an actual Request object here, for body to do its job
        request = DummyRequest({})
        request.method = 'PUT'
        request.body = '{"type": "Point", "coordinates": [45, 5]}'
        response = proto.update(request, 'a')
        self.assertEqual(response.status_int, 400)
开发者ID:gberaudo,项目名称:papyrus,代码行数:19,代码来源:test_protocol.py

示例3: test_update_notfound

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import update [as 别名]
    def test_update_notfound(self):
        from papyrus.protocol import Protocol
        from pyramid.testing import DummyRequest

        MappedClass = self._get_mapped_class()

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {}
        proto = Protocol(MockSession, MappedClass, "geom")
        # we need an actual Request object here, for body to do its job
        request = DummyRequest({})
        request.method = 'PUT'
        request.body = '{"type": "Feature", "id": 1, "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}'  # NOQA
        response = proto.update(request, 1)
        self.assertEqual(response.status_int, 404)
开发者ID:gberaudo,项目名称:papyrus,代码行数:19,代码来源:test_protocol.py

示例4: test_update

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import update [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

示例5: test_update_notfound

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

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

        # a mock session specific to this test
        class MockSession(object):
            def query(self, mapped_class):
                return {}
        proto = Protocol(MockSession, MappedClass, "geom")
        # we need an actual Request object here, for body_file to do its job
        request = Request({})
        request.body_file = StringIO('{"type": "Feature", "id": 1, "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}')
        response = proto.update(request, 1)
        self.assertEqual(response.status_int, 404)
开发者ID:fredj,项目名称:papyrus,代码行数:21,代码来源:test_protocol.py


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