Ticket #15653: 15653_test.patch

File 15653_test.patch, 2.5 KB (added by nott, 11 years ago)

Regression test.

  • tests/admin_changelist/tests.py

    diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
    index fd43396..82cce68 100644
    a b import datetime  
    55from django.contrib import admin
    66from django.contrib.admin.options import IncorrectLookupParameters
    77from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR
     8from django.contrib.admin.templatetags.admin_list import pagination
    89from django.contrib.auth.models import User
    910from django.core.urlresolvers import reverse
    1011from django.template import Context, Template
    class ChangeListTests(TestCase):  
    564565        response = m.changelist_view(request)
    565566        self.assertEqual(response.context_data['cl'].list_filter, ('parent', 'name', 'age'))
    566567
     568    def test_pagination_page_range(self):
     569        """
     570        Regression tests for ticket #15653: testing that the number of pages
     571        generated for changelist views are correct.
     572        """
     573        # instantiating and setting up ChangeList object
     574        m = GroupAdmin(Group, admin.site)
     575        request = self.factory.get('/group/')
     576        cl = ChangeList(request, Group, m.list_display,
     577                m.list_display_links, m.list_filter, m.date_hierarchy,
     578                m.search_fields, m.list_select_related, m.list_per_page,
     579                m.list_max_show_all, m.list_editable, m)
     580        per_page = cl.list_per_page = 10
     581        DOT = '.'
     582
     583        for page_num, objects_count, expected_page_range in [
     584            (0, per_page, []),
     585            (0, per_page * 2, range(2)),
     586            (5, per_page * 11, range(11)),
     587            (5, per_page * 12, [0, 1, 2, 3, 4, 5, 6, 7, 8, DOT, 10, 11]),
     588            (6, per_page * 12, [0, 1, DOT, 3, 4, 5, 6, 7, 8, 9, 10, 11]),
     589            (6, per_page * 13, [0, 1, DOT, 3, 4, 5, 6, 7, 8, 9, DOT, 11, 12]),
     590        ]:
     591            # assuming we have exactly `objects_count` objects
     592            Group.objects.all().delete()
     593            for i in xrange(objects_count):
     594                Group.objects.create(name='test band')
     595
     596            # setting page number and calculating page range
     597            cl.page_num = page_num
     598            cl.get_results(request)
     599            real_page_range = pagination(cl)['page_range']
     600
     601            self.assertEqual(
     602                expected_page_range,
     603                real_page_range,
     604            )
     605
     606
    567607class AdminLogNodeTestCase(TestCase):
    568608
    569609    def test_get_admin_log_templatetag_custom_user(self):
Back to Top