Ticket #13897: object_list_tests.diff

File object_list_tests.diff, 3.7 KB (added by Dougal Matthews, 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 *  
    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..6b1fed0
    - +  
     1# coding: utf-8
     2from django.test import TestCase
     3from regressiontests.views.models import Article, Author, DateArticle
     4
     5class 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 = {  
    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', object_list_no_paginate_by),
     121)
     122
    108123# a view that raises an exception for the debug view
    109124urlpatterns += patterns('',
    110125    (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