Ticket #13897: object_list_tests.diff
File object_list_tests.diff, 3.7 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..6b1fed0
- + 1 # coding: utf-8 2 from django.test import TestCase 3 from regressiontests.views.models import Article, Author, DateArticle 4 5 class ObjectListTest(TestCase): 6 fixtures = ['testdata.json'] 7 8 def check_pagination(self, url, expected_status_code, object_count=None): 9 10 response = self.client.get(url) 11 self.assertEqual(response.status_code, expected_status_code) 12 13 if object_count: 14 self.assertEqual(response.context['is_paginated'], True) 15 self.assertEqual(len(response.context['page_obj'].object_list), object_count) 16 17 return response 18 19 def test_finds_pages(self): 20 "" 21 22 # check page count doesn't start at 0 23 response = self.check_pagination('/views/object_list/page0/', 404) 24 25 response = self.check_pagination('/views/object_list/page/', 200, ) 26 response = self.check_pagination('/views/object_list/page1/', 200, 2) 27 response = self.check_pagination('/views/object_list/page2/', 200, 1) 28 response = self.check_pagination('/views/object_list/pagelast/', 200, 1) 29 response = self.check_pagination('/views/object_list/pagenotlast/', 404) 30 31 response = self.check_pagination('/views/object_list/page3/', 404) 32 33 34 def test_no_paginate_by(self): 35 36 response = self.check_pagination('/views/object_list_no_paginate_by/page1/', 200) 37 self.assertEqual(response.context['is_paginated'], False) 38 39 No newline at end of file -
tests/regressiontests/views/urls.py
diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py index f5675d0..9cf821c 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', object_list_no_paginate_by), 121 ) 122 108 123 # a view that raises an exception for the debug view 109 124 urlpatterns += patterns('', 110 125 (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