| 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 | |