MCPcopy Create free account
hub / github.com/encode/django-rest-framework / test_single_offset

Method test_single_offset

tests/test_pagination.py:414–441  ·  view source on GitHub ↗

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.

(self)

Source from the content-addressed store, hash-verified

412 assert queryset is None
413
414 def test_single_offset(self):
415 """
416 When the offset is not a multiple of the limit we get some edge cases:
417 * The first page should still be offset zero.
418 * We may end up displaying an extra page in the pagination control.
419 """
420 request = Request(factory.get('/', {'limit': 5, 'offset': 1}))
421 queryset = self.paginate_queryset(request)
422 content = self.get_paginated_content(queryset)
423 context = self.get_html_context()
424 assert queryset == [2, 3, 4, 5, 6]
425 assert content == {
426 'results': [2, 3, 4, 5, 6],
427 'previous': 'http://testserver/?limit=5',
428 'next': 'http://testserver/?limit=5&offset=6',
429 'count': 100
430 }
431 assert context == {
432 'previous_url': 'http://testserver/?limit=5',
433 'next_url': 'http://testserver/?limit=5&offset=6',
434 'page_links': [
435 PageLink('http://testserver/?limit=5', 1, False, False),
436 PageLink('http://testserver/?limit=5&offset=1', 2, True, False),
437 PageLink('http://testserver/?limit=5&offset=6', 3, False, False),
438 PAGE_BREAK,
439 PageLink('http://testserver/?limit=5&offset=96', 21, False, False),
440 ]
441 }
442
443 def test_first_offset(self):
444 request = Request(factory.get('/', {'limit': 5, 'offset': 5}))

Callers

nothing calls this directly

Calls 5

paginate_querysetMethod · 0.95
get_paginated_contentMethod · 0.95
get_html_contextMethod · 0.95
RequestClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected