def test_ending_offset(self):
     request = Request(factory.get('/', {'limit': 5, 'offset': 95}))
     queryset = self.paginate_queryset(request)
     content = self.get_paginated_content(queryset)
     context = self.get_html_context()
     assert queryset == [96, 97, 98, 99, 100]
     assert content == {
         'results': [96, 97, 98, 99, 100],
         'previous': 'http://testserver/?limit=5&offset=90',
         'next': None,
         'count': 100
     }
     assert context == {
         'previous_url':
         'http://testserver/?limit=5&offset=90',
         'next_url':
         None,
         'page_links': [
             PageLink('http://testserver/?limit=5', 1, False, False),
             PAGE_BREAK,
             PageLink('http://testserver/?limit=5&offset=85', 18, False,
                      False),
             PageLink('http://testserver/?limit=5&offset=90', 19, False,
                      False),
             PageLink('http://testserver/?limit=5&offset=95', 20, True,
                      False),
         ]
     }
 def test_middle_offset(self):
     request = Request(factory.get('/', {'limit': 5, 'offset': 10}))
     queryset = self.paginate_queryset(request)
     content = self.get_paginated_content(queryset)
     context = self.get_html_context()
     assert queryset == [11, 12, 13, 14, 15]
     assert content == {
         'results': [11, 12, 13, 14, 15],
         'previous': 'http://testserver/?limit=5&offset=5',
         'next': 'http://testserver/?limit=5&offset=15',
         'count': 100
     }
     assert context == {
         'previous_url':
         'http://testserver/?limit=5&offset=5',
         'next_url':
         'http://testserver/?limit=5&offset=15',
         'page_links': [
             PageLink('http://testserver/?limit=5', 1, False, False),
             PageLink('http://testserver/?limit=5&offset=5', 2, False,
                      False),
             PageLink('http://testserver/?limit=5&offset=10', 3, True,
                      False),
             PageLink('http://testserver/?limit=5&offset=15', 4, False,
                      False),
             PAGE_BREAK,
             PageLink('http://testserver/?limit=5&offset=95', 20, False,
                      False),
         ]
     }
 def test_single_offset(self):
     """
     When the offset is not a multiple of the limit we get some edge cases:
     * The first page should still be offset zero.
     * We may end up displaying an extra page in the pagination control.
     """
     request = Request(factory.get('/', {'limit': 5, 'offset': 1}))
     queryset = self.paginate_queryset(request)
     content = self.get_paginated_content(queryset)
     context = self.get_html_context()
     assert queryset == [2, 3, 4, 5, 6]
     assert content == {
         'results': [2, 3, 4, 5, 6],
         'previous': 'http://testserver/?limit=5',
         'next': 'http://testserver/?limit=5&offset=6',
         'count': 100
     }
     assert context == {
         'previous_url':
         'http://testserver/?limit=5',
         'next_url':
         'http://testserver/?limit=5&offset=6',
         'page_links': [
             PageLink('http://testserver/?limit=5', 1, False, False),
             PageLink('http://testserver/?limit=5&offset=1', 2, True,
                      False),
             PageLink('http://testserver/?limit=5&offset=6', 3, False,
                      False),
             PAGE_BREAK,
             PageLink('http://testserver/?limit=5&offset=96', 21, False,
                      False),
         ]
     }
 def test_no_offset(self):
     request = Request(factory.get('/', {'limit': 5}))
     queryset = self.paginate_queryset(request)
     content = self.get_paginated_content(queryset)
     context = self.get_html_context()
     assert queryset == [1, 2, 3, 4, 5]
     assert content == {
         'results': [1, 2, 3, 4, 5],
         'previous': None,
         'next': 'http://testserver/?limit=5&offset=5',
         'count': 100
     }
     assert context == {
         'previous_url':
         None,
         'next_url':
         'http://testserver/?limit=5&offset=5',
         'page_links': [
             PageLink('http://testserver/?limit=5', 1, True, False),
             PageLink('http://testserver/?limit=5&offset=5', 2, False,
                      False),
             PageLink('http://testserver/?limit=5&offset=10', 3, False,
                      False),
             PAGE_BREAK,
             PageLink('http://testserver/?limit=5&offset=95', 20, False,
                      False),
         ]
     }
     assert self.pagination.display_page_controls
     assert isinstance(self.pagination.to_html(), type(''))
 def test_last_page(self):
     request = Request(factory.get('/', {'page': 'last'}))
     queryset = self.paginate_queryset(request)
     content = self.get_paginated_content(queryset)
     context = self.get_html_context()
     assert queryset == [96, 97, 98, 99, 100]
     assert content == {
         'results': [96, 97, 98, 99, 100],
         'previous': 'http://testserver/?page=19',
         'next': None,
         'count': 100
     }
     assert context == {
         'previous_url':
         'http://testserver/?page=19',
         'next_url':
         None,
         'page_links': [
             PageLink('http://testserver/', 1, False, False),
             PAGE_BREAK,
             PageLink('http://testserver/?page=18', 18, False, False),
             PageLink('http://testserver/?page=19', 19, False, False),
             PageLink('http://testserver/?page=20', 20, True, False),
         ]
     }
 def test_second_page(self):
     request = Request(factory.get('/', {'page': 2}))
     queryset = self.paginate_queryset(request)
     content = self.get_paginated_content(queryset)
     context = self.get_html_context()
     assert queryset == [6, 7, 8, 9, 10]
     assert content == {
         'results': [6, 7, 8, 9, 10],
         'previous': 'http://testserver/',
         'next': 'http://testserver/?page=3',
         'count': 100
     }
     assert context == {
         'previous_url':
         'http://testserver/',
         'next_url':
         'http://testserver/?page=3',
         'page_links': [
             PageLink('http://testserver/', 1, False, False),
             PageLink('http://testserver/?page=2', 2, True, False),
             PageLink('http://testserver/?page=3', 3, False, False),
             PAGE_BREAK,
             PageLink('http://testserver/?page=20', 20, False, False),
         ]
     }