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


Python Protocol.create方法代码示例

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


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

示例1: test_create

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

示例2: test_create_update

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import create [as 别名]
    def test_create_update(self):
        from papyrus.protocol import Protocol
        from pyramid.testing import DummyRequest
        from geojson import Feature, FeatureCollection
        from shapely.geometry import Point

        MappedClass = self._get_mapped_class()

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

            def flush(self):
                pass

        proto = Protocol(MockSession, MappedClass, 'geom')

        # we need an actual Request object here, for body to do its job
        request = DummyRequest({})
        request.method = 'POST'
        request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "id": "a", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "id": "b", "properties": {"text": "bar"}, "geometry": {"type": "Point", "coordinates": [46, 6]}}]}'  # NOQA
        features = proto.create(request)

        self.assertTrue(isinstance(features, FeatureCollection))
        self.assertEqual(len(features.features), 2)
        self.assertEqual(features.features[0].id, 'a')
        self.assertEqual(features.features[0].text, 'foo')
        self.assertTrue(features.features[0].geom.shape.equals(Point(45, 5)))
        self.assertEqual(features.features[1].id, 'b')
        self.assertEqual(features.features[1].text, 'bar')
        self.assertTrue(features.features[1].geom.shape.equals(Point(46, 6)))
开发者ID:gberaudo,项目名称:papyrus,代码行数:35,代码来源:test_protocol.py

示例3: test_create_badrequest

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import create [as 别名]
    def test_create_badrequest(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")
        # we need an actual Request object here, for body to do its job
        request = DummyRequest({})
        request.method = 'POST'
        request.body = '{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}'  # NOQA
        response = proto.create(request)
        self.assertEqual(response.status_int, 400)
开发者ID:gberaudo,项目名称:papyrus,代码行数:17,代码来源:test_protocol.py

示例4: test_create_empty

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

        # we need an actual Request object here, for body to do its job
        request = DummyRequest({})
        request.method = 'POST'
        request.body = '{"type": "FeatureCollection", "features": []}'
        resp = proto.create(request)
        self.assertEqual(resp, None)
开发者ID:gberaudo,项目名称:papyrus,代码行数:18,代码来源:test_protocol.py

示例5: test_create_forbidden

# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import create [as 别名]
    def test_create_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 = '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]}}]}'  # NOQA
        response = proto.create(request)
        self.assertTrue(response.headers.get('Allow') == "GET, HEAD")
        self.assertEqual(response.status_int, 405)
开发者ID:gberaudo,项目名称:papyrus,代码行数:18,代码来源:test_protocol.py

示例6: test_create_empty

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

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

        proto = Protocol(Session, MappedClass, "geom")

        # we need an actual Request object here, for body_file to do its job
        request = Request({})
        request.body_file = StringIO('{"type": "FeatureCollection", "features": []}')
        resp = proto.create(request)
        self.assertEqual(resp, None)
开发者ID:fredj,项目名称:papyrus,代码行数:19,代码来源:test_protocol.py


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