Fixed #13897 -- Added tests for pagination feature of the generic object_list view. Thanks, d0ugal and SmileyChris.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13965 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e77f16144b
commit
d69c7eab04
|
@ -2,6 +2,7 @@ from debug import *
|
|||
from defaults import *
|
||||
from generic.create_update import *
|
||||
from generic.date_based import *
|
||||
from generic.object_list import *
|
||||
from generic.simple import *
|
||||
from i18n import *
|
||||
from specials import *
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
from django.test import TestCase
|
||||
|
||||
|
||||
class ObjectListTest(TestCase):
|
||||
fixtures = ['testdata.json']
|
||||
|
||||
def check_pagination(self, url, expected_status_code, object_count=None):
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, expected_status_code)
|
||||
|
||||
if object_count:
|
||||
self.assertEqual(response.context['is_paginated'], True)
|
||||
self.assertEqual(len(response.context['page_obj'].object_list),
|
||||
object_count)
|
||||
|
||||
return response
|
||||
|
||||
def test_finds_pages(self):
|
||||
# Check page count doesn't start at 0.
|
||||
self.check_pagination('/views/object_list/page0/', 404)
|
||||
|
||||
# Check basic pages.
|
||||
self.check_pagination('/views/object_list/page/', 200, 2)
|
||||
self.check_pagination('/views/object_list/page1/', 200, 2)
|
||||
self.check_pagination('/views/object_list/page2/', 200, 1)
|
||||
self.check_pagination('/views/object_list/page3/', 404)
|
||||
|
||||
# Check the special "last" page.
|
||||
self.check_pagination('/views/object_list/pagelast/', 200, 1)
|
||||
self.check_pagination('/views/object_list/pagenotlast/', 404)
|
||||
|
||||
def test_no_paginate_by(self):
|
||||
# Ensure that the view isn't paginated by default.
|
||||
url = '/views/object_list_no_paginate_by/page1/'
|
||||
response = self.check_pagination(url, 200)
|
||||
self.assertEqual(response.context['is_paginated'], False)
|
|
@ -31,6 +31,16 @@ date_based_info_dict = {
|
|||
'date_field': 'date_created',
|
||||
'month_format': '%m',
|
||||
}
|
||||
|
||||
object_list_dict = {
|
||||
'queryset': Article.objects.all(),
|
||||
'paginate_by': 2,
|
||||
}
|
||||
|
||||
object_list_no_paginate_by = {
|
||||
'queryset': Article.objects.all(),
|
||||
}
|
||||
|
||||
numeric_days_info_dict = dict(date_based_info_dict, day_format='%d')
|
||||
|
||||
date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all())
|
||||
|
@ -104,6 +114,12 @@ urlpatterns += patterns('django.views.generic.create_update',
|
|||
'update_object', dict(slug_field='slug', model=UrlArticle)),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('django.views.generic.list_detail',
|
||||
(r'^object_list/page(?P<page>[\w]*)/$', 'object_list', object_list_dict),
|
||||
(r'^object_list_no_paginate_by/page(?P<page>[0-9]+)/$', 'object_list',
|
||||
object_list_no_paginate_by),
|
||||
)
|
||||
|
||||
# a view that raises an exception for the debug view
|
||||
urlpatterns += patterns('',
|
||||
(r'^raises/$', views.raises),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{ object_list }}
|
Loading…
Reference in New Issue