mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-10 08:15:57 +01:00
Raise a validation error when attempting to set ordering with cursor pagination
This commit is contained in:
@@ -53,6 +53,10 @@ class NetBoxPagination(LimitOffsetPagination):
|
||||
raise ValidationError(
|
||||
f"'{self.start_query_param}' and '{self.offset_query_param}' are mutually exclusive."
|
||||
)
|
||||
if 'ordering' in request.query_params:
|
||||
raise ValidationError(
|
||||
f"'{self.start_query_param}' and 'ordering' are mutually exclusive."
|
||||
)
|
||||
|
||||
self.count = None
|
||||
self.offset = 0
|
||||
|
||||
@@ -104,3 +104,10 @@ class OptionalLimitOffsetPaginationTest(TestCase):
|
||||
request = self._make_drf_request(query_params={'start': '1', 'offset': '10'})
|
||||
with self.assertRaises(ValidationError):
|
||||
self.paginator.paginate_queryset(queryset, request)
|
||||
|
||||
def test_cursor_and_ordering_conflict_raises_validation_error(self):
|
||||
"""paginate_queryset() raises ValidationError when both start and ordering are specified"""
|
||||
queryset = Token.objects.all().order_by('created')
|
||||
request = self._make_drf_request(query_params={'start': '1', 'ordering': 'created'})
|
||||
with self.assertRaises(ValidationError):
|
||||
self.paginator.paginate_queryset(queryset, request)
|
||||
|
||||
@@ -231,6 +231,12 @@ class APIPaginationTestCase(APITestCase):
|
||||
response = self.client.get(f'{self.url}?start=1&offset=10', format='json', **self.header)
|
||||
self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_cursor_and_ordering_conflict(self):
|
||||
"""Specifying both start and ordering returns a 400 error."""
|
||||
with disable_warnings('django.request'):
|
||||
response = self.client.get(f'{self.url}?start=1&ordering=name', format='json', **self.header)
|
||||
self.assertHttpStatus(response, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_cursor_negative_start(self):
|
||||
"""Negative start value returns a 400 error."""
|
||||
with disable_warnings('django.request'):
|
||||
|
||||
Reference in New Issue
Block a user