Ticket #13897: 13897.diff
File 13897.diff, 3.5 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/views/tests/__init__.py
diff --git a/tests/regressiontests/views/tests/__init__.py b/tests/regressiontests/views/tests/__init__.py index 697968e..b9eee34 100644
a b from debug import * 2 2 from defaults import * 3 3 from generic.create_update import * 4 4 from generic.date_based import * 5 from generic.object_list import * 5 6 from i18n import * 6 7 from specials import * 7 8 from static import * -
new file tests/regressiontests/views/tests/generic/object_list.py
diff --git a/tests/regressiontests/views/tests/generic/object_list.py b/tests/regressiontests/views/tests/generic/object_list.py new file mode 100644 index 0000000..4f902ee
- + 1 from django.test import TestCase 2 3 4 class ObjectListTest(TestCase): 5 fixtures = ['testdata.json'] 6 7 def check_pagination(self, url, expected_status_code, object_count=None): 8 response = self.client.get(url) 9 self.assertEqual(response.status_code, expected_status_code) 10 11 if object_count: 12 self.assertEqual(response.context['is_paginated'], True) 13 self.assertEqual(len(response.context['page_obj'].object_list), 14 object_count) 15 16 return response 17 18 def test_finds_pages(self): 19 # Check page count doesn't start at 0. 20 self.check_pagination('/views/object_list/page0/', 404) 21 22 # Check basic pages. 23 self.check_pagination('/views/object_list/page/', 200, 2) 24 self.check_pagination('/views/object_list/page1/', 200, 2) 25 self.check_pagination('/views/object_list/page2/', 200, 1) 26 self.check_pagination('/views/object_list/page3/', 404) 27 28 # Check the special "last" page. 29 self.check_pagination('/views/object_list/pagelast/', 200, 1) 30 self.check_pagination('/views/object_list/pagenotlast/', 404) 31 32 def test_no_paginate_by(self): 33 # Ensure that the view isn't paginated by default. 34 url = '/views/object_list_no_paginate_by/page1/' 35 response = self.check_pagination(url, 200) 36 self.assertEqual(response.context['is_paginated'], False) -
tests/regressiontests/views/urls.py
diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py index f5675d0..9b57bfe 100644
a b date_based_info_dict = { 31 31 'date_field': 'date_created', 32 32 'month_format': '%m', 33 33 } 34 35 object_list_dict = { 36 'queryset': Article.objects.all(), 37 'paginate_by': 2, 38 } 39 40 object_list_no_paginate_by = { 41 'queryset': Article.objects.all(), 42 } 43 34 44 numeric_days_info_dict = dict(date_based_info_dict, day_format='%d') 35 45 36 46 date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all()) … … urlpatterns += patterns('django.views.generic.create_update', 105 115 'update_object', dict(slug_field='slug', model=UrlArticle)), 106 116 ) 107 117 118 urlpatterns += patterns('django.views.generic.list_detail', 119 (r'^object_list/page(?P<page>[\w]*)/$', 'object_list', object_list_dict), 120 (r'^object_list_no_paginate_by/page(?P<page>[0-9]+)/$', 'object_list', 121 object_list_no_paginate_by), 122 ) 123 108 124 # a view that raises an exception for the debug view 109 125 urlpatterns += patterns('', 110 126 (r'^raises/$', views.raises), -
new file tests/templates/views/article_list.html
diff --git a/tests/templates/views/article_list.html b/tests/templates/views/article_list.html new file mode 100644 index 0000000..3840895
- + 1 {{ object_list }} 2 No newline at end of file