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


Python Protocol._query方法代码示例

本文整理汇总了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))
开发者ID:sbrunner,项目名称:papyrus,代码行数:60,代码来源:test_protocol.py

示例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)
开发者ID:gberaudo,项目名称:papyrus,代码行数:22,代码来源:test_protocol.py


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