Example #1
0
 def test_middle_range(self):
     data = [{'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}, {'id': 5}]
     request = self.request('get', '/', {'range': '[2,3]'})
     p = pagination.ContentRangeHeaderPagination()
     qs = p.paginate_queryset(data, request)
     assert len(qs) == 2
     resp = p.get_paginated_response(data)
     assert 'Content-Range' in resp
     assert resp['Content-Range'] == 'items 2-3/5'
Example #2
0
 def test_range_start_too_high(self):
     data = [{'id': 1}, {'id': 2}, {'id': 3}]
     request = self.request('get', '/', {'range': '[2,1]'})
     p = pagination.ContentRangeHeaderPagination()
     qs = p.paginate_queryset(data, request)
     assert len(qs) == 1
     resp = p.get_paginated_response(data)
     assert 'Content-Range' in resp
     assert resp['Content-Range'] == 'items 1-1/3'
Example #3
0
 def test_data(self):
     data = [{'id': 1}, {'id': 2}, {'id': 3}]
     request = self.request('get', '/')
     p = pagination.ContentRangeHeaderPagination()
     qs = p.paginate_queryset(data, request)
     assert len(qs) == 3
     resp = p.get_paginated_response(data)
     assert 'Content-Range' in resp
     assert resp['Content-Range'] == 'items 0-2/3'
Example #4
0
    def test_invalid_range_format(self):
        data = [{'id': 1}, {'id': 2}, {'id': 3}, {'id': 4}, {'id': 5}]
        request = self.request('get', '/', {'range': '[2,3'})
        p = pagination.ContentRangeHeaderPagination()
        qs = p.paginate_queryset(data, request)
        assert qs is None
        resp = p.get_paginated_response(data)
        assert 'Content-Range' in resp
        assert resp['Content-Range'] == 'items 0-4/5'

        request = self.request('get', '/', {'range': '2,3'})
        p = pagination.ContentRangeHeaderPagination()
        qs = p.paginate_queryset(data, request)
        assert qs is None
        resp = p.get_paginated_response(data)
        assert 'Content-Range' in resp
        assert resp['Content-Range'] == 'items 0-4/5'

        request = self.request('get', '/', {'range': '[2,3,4]'})
        p = pagination.ContentRangeHeaderPagination()
        qs = p.paginate_queryset(data, request)
        assert qs is None
        resp = p.get_paginated_response(data)
        assert 'Content-Range' in resp
        assert resp['Content-Range'] == 'items 0-4/5'

        request = self.request('get', '/', {'range': '["foo"]'})
        p = pagination.ContentRangeHeaderPagination()
        qs = p.paginate_queryset(data, request)
        assert qs is None
        resp = p.get_paginated_response(data)
        assert 'Content-Range' in resp
        assert resp['Content-Range'] == 'items 0-4/5'

        request = self.request('get', '/', {'range': '['})
        p = pagination.ContentRangeHeaderPagination()
        qs = p.paginate_queryset(data, request)
        assert qs is None
        resp = p.get_paginated_response(data)
        assert 'Content-Range' in resp
        assert resp['Content-Range'] == 'items 0-4/5'

        request = self.request('get', '/', {'range': 'invalid'})
        p = pagination.ContentRangeHeaderPagination()
        qs = p.paginate_queryset(data, request)
        assert qs is None
        resp = p.get_paginated_response(data)
        assert 'Content-Range' in resp
        assert resp['Content-Range'] == 'items 0-4/5'