本文整理汇总了Python中papyrus.protocol.Protocol._query方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol._query方法的具体用法?Python Protocol._query怎么用?Python Protocol._query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类papyrus.protocol.Protocol
的用法示例。
在下文中一共展示了Protocol._query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test___query
# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import _query [as 别名]
def test___query(self):
from papyrus.protocol import Protocol, create_attr_filter
from mock import patch
engine = self._get_engine()
Session = self._get_session(engine)
MappedClass = self._get_mapped_class()
proto = Protocol(Session, MappedClass, "geom")
request = testing.DummyRequest()
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("SELECT" in query_to_str(query, engine))
request = testing.DummyRequest(params={"queryable": "id", "id__eq": "1"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("WHERE" in query_to_str(query, engine))
request = testing.DummyRequest(params={"queryable": "id", "id__eq": "1"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
filter = create_attr_filter(request, MappedClass)
query = proto._query(testing.DummyRequest(), filter=filter)
self.assertTrue("WHERE" in query_to_str(query, engine))
request = testing.DummyRequest(params={"limit": "2"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("LIMIT" in query_to_str(query, engine))
request = testing.DummyRequest(params={"maxfeatures": "2"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("LIMIT" in query_to_str(query, engine))
request = testing.DummyRequest(params={"limit": "2", "offset": "10"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("OFFSET" in query_to_str(query, engine))
request = testing.DummyRequest(params={"order_by": "text"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("ORDER BY" in query_to_str(query, engine))
self.assertTrue("ASC" in query_to_str(query, engine))
request = testing.DummyRequest(params={"sort": "text"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("ORDER BY" in query_to_str(query, engine))
self.assertTrue("ASC" in query_to_str(query, engine))
request = testing.DummyRequest(params={"order_by": "text", "dir": "DESC"})
with patch('sqlalchemy.orm.query.Query.all', lambda q : q):
query = proto._query(request)
self.assertTrue("ORDER BY" in query_to_str(query, engine))
self.assertTrue("DESC" in query_to_str(query, engine))
示例2: test_read_many
# 需要导入模块: from papyrus.protocol import Protocol [as 别名]
# 或者: from papyrus.protocol.Protocol import _query [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)