mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Test improper configuration of ordering
just checking that the ImproperlyConfigured error is raised if ordering_fields, serializer_class and get_serializer_class are not provided in the view.
This commit is contained in:
parent
4bcc8cda89
commit
af22135abb
|
@ -776,6 +776,20 @@ class OrderingFilterTests(TestCase):
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_ordering_with_improper_configuration(self):
|
||||||
|
class OrderingListView(generics.ListAPIView):
|
||||||
|
queryset = OrderingFilterModel.objects.all()
|
||||||
|
filter_backends = (filters.OrderingFilter,)
|
||||||
|
ordering = ('title',)
|
||||||
|
# note: no ordering_fields and serializer_class
|
||||||
|
# or get_serializer_class speficied
|
||||||
|
|
||||||
|
view = OrderingListView.as_view()
|
||||||
|
request = factory.get('/', {'ordering': 'text'})
|
||||||
|
# BUG: I think this should raise ImproperlyConfigured
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
view(request)
|
||||||
|
|
||||||
|
|
||||||
class SensitiveOrderingFilterModel(models.Model):
|
class SensitiveOrderingFilterModel(models.Model):
|
||||||
username = models.CharField(max_length=20)
|
username = models.CharField(max_length=20)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user