Author: jezdez
Date: 2010-09-30 21:01:20 -0500 (Thu, 30 Sep 2010)
New Revision: 13965
Added:
django/trunk/tests/regressiontests/views/tests/generic/object_list.py
django/trunk/tests/templates/views/article_list.html
Modified:
django/trunk/tests/regressiontests/views/tests/__init__.py
django/trunk/tests/regressiontests/views/urls.py
Log:
Fixed #13897 -- Added tests for pagination feature of the generic object_list
view. Thanks, d0ugal and SmileyChris.
Modified: django/trunk/tests/regressiontests/views/tests/__init__.py
===================================================================
--- django/trunk/tests/regressiontests/views/tests/__init__.py 2010-10-01
02:00:52 UTC (rev 13964)
+++ django/trunk/tests/regressiontests/views/tests/__init__.py 2010-10-01
02:01:20 UTC (rev 13965)
@@ -2,6 +2,7 @@
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 *
Added: django/trunk/tests/regressiontests/views/tests/generic/object_list.py
===================================================================
--- django/trunk/tests/regressiontests/views/tests/generic/object_list.py
(rev 0)
+++ django/trunk/tests/regressiontests/views/tests/generic/object_list.py
2010-10-01 02:01:20 UTC (rev 13965)
@@ -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)
Modified: django/trunk/tests/regressiontests/views/urls.py
===================================================================
--- django/trunk/tests/regressiontests/views/urls.py 2010-10-01 02:00:52 UTC
(rev 13964)
+++ django/trunk/tests/regressiontests/views/urls.py 2010-10-01 02:01:20 UTC
(rev 13965)
@@ -31,6 +31,16 @@
'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 @@
'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),
Added: django/trunk/tests/templates/views/article_list.html
===================================================================
--- django/trunk/tests/templates/views/article_list.html
(rev 0)
+++ django/trunk/tests/templates/views/article_list.html 2010-10-01
02:01:20 UTC (rev 13965)
@@ -0,0 +1 @@
+{{ object_list }}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.