'Regression tests for ticket #15653: ensure the number of pages
generated for changelist views are correct.'

def test_pagination_page_range(self):

    m = GroupAdmin(Group, admin.site)
    request = self.factory.get(u'/group/')
    cl = ChangeList(request, Group, m.list_display, m.list_display_links, m.list_filter, m.date_hierarchy, m.search_fields, m.list_select_related, m.list_per_page, m.list_max_show_all, m.list_editable, m)
    per_page = cl.list_per_page = 10
    for (page_num, objects_count, expected_page_range) in [(0, per_page, []), (0, (per_page * 2), list(range(2))), (5, (per_page * 11), list(range(11))), (5, (per_page * 12), [0, 1, 2, 3, 4, 5, 6, 7, 8, u'.', 10, 11]), (6, (per_page * 12), [0, 1, u'.', 3, 4, 5, 6, 7, 8, 9, 10, 11]), (6, (per_page * 13), [0, 1, u'.', 3, 4, 5, 6, 7, 8, 9, u'.', 11, 12])]:
        Group.objects.all().delete()
        for i in range(objects_count):
            Group.objects.create(name=u'test    band')
        cl.page_num = page_num
        cl.get_results(request)
        real_page_range = pagination(cl)[u'page_range']
        self.assertListEqual(expected_page_range, list(real_page_range))
