Ticket #13897: 13897.diff

File 13897.diff, 3.5 KB (added by Chris Beaven, 14 years ago)

PEP tidied patch

  • 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 *  
    22from defaults import *
    33from generic.create_update import *
    44from generic.date_based import *
     5from generic.object_list import *
    56from i18n import *
    67from specials import *
    78from 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
    - +  
     1from django.test import TestCase
     2
     3
     4class 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 = {  
    3131    'date_field': 'date_created',
    3232    'month_format': '%m',
    3333}
     34
     35object_list_dict = {
     36    'queryset': Article.objects.all(),
     37    'paginate_by': 2,
     38}
     39
     40object_list_no_paginate_by = {
     41    'queryset': Article.objects.all(),
     42}
     43
    3444numeric_days_info_dict = dict(date_based_info_dict, day_format='%d')
    3545
    3646date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all())
    urlpatterns += patterns('django.views.generic.create_update',  
    105115        'update_object', dict(slug_field='slug', model=UrlArticle)),
    106116)
    107117
     118urlpatterns += 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
    108124# a view that raises an exception for the debug view
    109125urlpatterns += patterns('',
    110126    (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
Back to Top