本文整理汇总了Python中nailgun.objects.NodeCollection.scope方法的典型用法代码示例。如果您正苦于以下问题:Python NodeCollection.scope方法的具体用法?Python NodeCollection.scope怎么用?Python NodeCollection.scope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.objects.NodeCollection
的用法示例。
在下文中一共展示了NodeCollection.scope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pagination_of_node_collection
# 需要导入模块: from nailgun.objects import NodeCollection [as 别名]
# 或者: from nailgun.objects.NodeCollection import scope [as 别名]
def test_pagination_of_node_collection(self):
def assert_pagination_and_cont_rng(q, cr, sz, first, last, ttl, valid):
self.assertEqual(q.count(), sz)
self.assertEqual(cr.first, first)
self.assertEqual(cr.last, last)
self.assertEqual(cr.total, ttl)
self.assertEqual(cr.valid, valid)
self.env.create_nodes(5)
# test pagination limited to 2 first items
pagination = Pagination(limit=2)
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 2, 1, 2, 5, True)
# test invalid pagination
pagination = Pagination(offset=5)
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 0, 0, 0, 5, False)
# test limit=0, offset ignored
pagination = Pagination(limit=0, offset=999)
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 0, 0, 0, 5, True)
# test limit+offset+order_by
pagination = Pagination(limit=3, offset=1, order_by='-id')
q, cr = NodeCollection.scope(pagination)
assert_pagination_and_cont_rng(q, cr, 3, 2, 4, 5, True)
ids = sorted([i.id for i in self.env.nodes])
n = q.all()
self.assertEqual(n[0].id, ids[3])
self.assertEqual(n[1].id, ids[2])
self.assertEqual(n[2].id, ids[1])