bodhi/controllers.py | 10 ++++----
bodhi/search.py | 4 +--
bodhi/tests/test_controllers.py | 46 ++++++++++++++++++++++++++++++++++++----
3 files changed, 49 insertions(+), 11 deletions(-)
New commits:
commit 2681e88dd8c5acdeedfef58d9aab5e6aa57f6fd9
Author: Luke Macken <lmacken(a)redhat.com>
Date: Wed Jan 13 21:59:40 2010 -0500
Fix the pagination deprecation warnings, and add a test case for our limits
diff --git a/bodhi/controllers.py b/bodhi/controllers.py
index bd91405..f0c0605 100644
--- a/bodhi/controllers.py
+++ b/bodhi/controllers.py
@@ -210,7 +210,7 @@ class Root(controllers.RootController):
return updates
@expose(template="bodhi.templates.list", allow_json=True)
- @paginate('updates', limit=20, max_limit=50, allow_limit_override=True)
+ @paginate('updates', limit=20, max_limit=1000)
@validate(validators={
'release': validators.UnicodeString(),
'bugs': validators.UnicodeString(),
@@ -370,7 +370,7 @@ class Root(controllers.RootController):
@expose(template="bodhi.templates.mine", allow_json=True)
@identity.require(identity.not_anonymous())
- @paginate('updates', limit=20, max_limit=20, allow_limit_override=True)
+ @paginate('updates', limit=20, max_limit=20)
def mine(self):
""" List all updates submitted by the current user """
updates = PackageUpdate.select(
@@ -872,7 +872,7 @@ class Root(controllers.RootController):
raise redirect(updates[0].get_url())
@expose(template='bodhi.templates.list')
- @paginate('updates', limit=20, max_limit=20, allow_limit_override=True)
+ @paginate('updates', limit=20, max_limit=20)
def default(self, *args, **kw):
"""
This method allows for the following requests
@@ -1093,7 +1093,7 @@ class Root(controllers.RootController):
raise redirect('/')
@expose(template='bodhi.templates.comments')
- @paginate('comments', limit=20, max_limit=20, allow_limit_override=True)
+ @paginate('comments', limit=20, max_limit=20)
def comments(self):
data = Comment.select(Comment.q.author != 'bodhi',
orderBy=Comment.q.timestamp).reversed()
@@ -1177,7 +1177,7 @@ class Root(controllers.RootController):
return dict(updates=updates)
@expose(template="bodhi.templates.user")
- @paginate('updates', limit=25, max_limit=20, allow_limit_override=True)
+ @paginate('updates', limit=25, max_limit=20)
def user(self, username):
""" Return a list of updates submitted by a given person """
updates = PackageUpdate.select(PackageUpdate.q.submitter == username,
diff --git a/bodhi/search.py b/bodhi/search.py
index 4f13c9c..6e1913a 100644
--- a/bodhi/search.py
+++ b/bodhi/search.py
@@ -41,8 +41,8 @@ class SearchController(Controller):
@expose(template="bodhi.templates.search")
@validate(validators={ "search" : validators.UnicodeString() })
@error_handler(index)
- @paginate('updates', default_order='date_submitted', default_reversed=True,
- limit=25, allow_limit_override=True)
+ @paginate('updates', default_order='-date_submitted',
+ limit=20, max_limit=1000)
def default(self, search, *args, **kw):
results = set()
diff --git a/bodhi/tests/test_controllers.py b/bodhi/tests/test_controllers.py
index e066a0c..b63c9c6 100644
--- a/bodhi/tests/test_controllers.py
+++ b/bodhi/tests/test_controllers.py
@@ -1196,7 +1196,6 @@ class TestControllers(testutil.DBTest):
testutil.create_request('/updates/get_updates_from_builds?builds=' +
'kernel-2.6.29.1-111.fc7.x86_64%20TurboGears-1.0.2.2-2.fc7',
method='POST')
- import simplejson
json = simplejson.loads(cherrypy.response.body[0])
assert 'kernel-2.6.29.1-111.fc7.x86_64' in json
assert 'TurboGears-1.0.2.2-2.fc7' in json
@@ -1510,9 +1509,6 @@ class TestControllers(testutil.DBTest):
assert "Mark Critical Path update as Stable" in cherrypy.response.body[0]
def test_created_since(self):
- """
- Ensure admins can submit critpath updates for pending releases to stable
- """
session = login()
create_release()
params = {
@@ -1561,3 +1557,45 @@ class TestControllers(testutil.DBTest):
json = simplejson.loads(cherrypy.response.body[0])
assert json['num_items'] == 0
+
+ def test_query_limit(self):
+ session = login()
+ create_release()
+ params = {
+ 'builds' : 'kernel-2.6.31-1.fc7',
+ 'release' : 'Fedora 7',
+ 'type_' : 'bugfix',
+ 'bugs' : '',
+ 'notes' : 'foobar',
+ 'stable_karma' : 1,
+ 'request': None,
+ 'unstable_karma' : -1,
+ }
+ #update = PackageUpdate.byTitle(params['builds'])
+
+ # Create 100 updates
+ for prefix in xrange(100):
+ update = params.copy()
+ update['builds'] = '%s%d%s' % (update['builds'][0], prefix,
+ update['builds'][1:])
+ self.save_update(update, session)
+
+ assert PackageUpdate.select().count() == 100, PackageUpdate.select().count()
+
+ ## Test default limit
+ testutil.create_request('/updates/list?tg_format=json', method='GET',
+ headers=session)
+
+ assert '100 updates found' in cherrypy.response.body[0], cherrypy.response.body[0]
+ json = simplejson.loads(cherrypy.response.body[0])
+ assert json['num_items'] == 100, json['num_items']
+ assert len(json['updates']) == 20, len(json['updates'])
+
+ ## Try getting all 100
+ testutil.create_request('/updates/list?tg_format=json&tg_paginate_limit=100',
+ method='GET', headers=session)
+
+ assert '100 updates found' in cherrypy.response.body[0], cherrypy.response.body[0]
+ json = simplejson.loads(cherrypy.response.body[0])
+ assert json['num_items'] == 100, json['num_items']
+ assert len(json['updates']) == 100, len(json['updates'])