def test_too_high_limit_raises_error(self): paginator = OffsetPaginator() with pytest.raises(errors.InvalidPageValue) as exc_info: paginator.paginate({'limit': '101'}) assert exc_info.value.source_parameter == 'page[limit]' assert exc_info.value.detail == ( 'limit cannot exceed maximum page size of 100')
def test_invalid_params(self): paginator = OffsetPaginator() with pytest.raises(errors.InvalidPageFormat): paginator.paginate('foobar')
def test_invalid_limit_type(self): paginator = OffsetPaginator() with pytest.raises(errors.InvalidPageValue) as exc_info: paginator.paginate({'limit': 'foobar'}) assert exc_info.value.source_parameter == 'page[limit]' assert exc_info.value.detail == 'limit must be an integer'
def test_too_low_offset_raises_error(self): paginator = OffsetPaginator() with pytest.raises(errors.InvalidPageValue) as exc_info: paginator.paginate({'offset': '-1'}) assert exc_info.value.source_parameter == 'page[offset]' assert exc_info.value.detail == 'offset must be at least 0'
def test_defaults(self): paginator = OffsetPaginator() pagination = paginator.paginate({}) assert pagination.offset == 0 assert pagination.limit == 20
def test_extra_parameters_raises_error(self): paginator = OffsetPaginator() with pytest.raises(errors.InvalidPageParameter) as exc_info: paginator.paginate({'foo': 'bar'}) assert exc_info.value.source_parameter == 'page[foo]'
def test_can_override_paginator(self, make_resource): paginator = OffsetPaginator() resource = make_resource(paginator=paginator) assert resource.paginator is paginator