本文整理汇总了Python中papyrus.protocol.Protocol.read方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.read方法的具体用法?Python Protocol.read怎么用?Python Protocol.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类papyrus.protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_notfound
# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import read [as 别名]
def test_read_notfound(self):
from papyrus.protocol import Protocol
from pyramid.httpexceptions import HTTPNotFound
class Session(object):
def query(self, mapped_class):
return {'a': None}
proto = Protocol(Session, self._get_mapped_class(), 'geom')
request = testing.DummyRequest()
resp = proto.read(request, id='a')
self.assertTrue(isinstance(resp, HTTPNotFound))
示例2: test_read_id
# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import read [as 别名]
def test_read_id(self):
from papyrus.protocol import Protocol
from shapely.geometry import Point
from geojson import Feature
class Session(object):
def query(self, mapped_class):
feature = Feature(id='a', geometry=Point(1, 2),
properties=dict(text='foo'))
return {'a': mapped_class(feature)}
proto = Protocol(Session, self._get_mapped_class(), 'geom')
request = testing.DummyRequest()
feature = proto.read(request, id='a')
self.assertEqual(feature.id, 'a')
self.assertEqual(feature.properties['text'], 'foo')
示例3: test_read_many
# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import read [as 别名]
def test_read_many(self):
from papyrus.protocol import Protocol
from shapely.geometry import Point
from geojson import Feature, FeatureCollection
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
proto = Protocol(Session, MappedClass, 'geom')
def _query(request, filter):
f1 = Feature(geometry=Point(1, 2))
f2 = Feature(geometry=Point(2, 3))
return [MappedClass(f1), MappedClass(f2)]
proto._query = _query
features = proto.read(testing.DummyRequest())
self.assertTrue(isinstance(features, FeatureCollection))
self.assertEqual(len(features.features), 2)