Skip to content

Commit

Permalink
add test for django-filter and ListAPIView #1086
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Oct 17, 2023
1 parent 6e4180b commit f7f75a9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/contrib/test_django_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import models
from django.db.models import F
from django.urls import include, path
from rest_framework import routers, serializers, viewsets
from rest_framework import generics, routers, serializers, viewsets
from rest_framework.test import APIClient

from drf_spectacular.types import OpenApiTypes
Expand Down Expand Up @@ -419,3 +419,20 @@ class XViewSet(viewsets.ModelViewSet):
assert schema['paths']['/x/']['get']['parameters'][0]['description'] == (
'* `one` - One\n* `two` - Two\n* `three` - Three'
)


@pytest.mark.contrib('django_filter')
def test_filter_on_listapiview(no_warnings):
class XListView(generics.ListAPIView):
queryset = Product.objects.all()
serializer_class = ProductSerializer
filter_backends = (DjangoFilterBackend,)
filterset_class = ProductFilter

def get_queryset(self):
return Product.objects.all().annotate(
price_vat=F('price') * 1.19
)

schema = generate_schema('/x/', view=XListView)
assert len(schema['paths']['/x/']['get']['parameters']) > 1

0 comments on commit f7f75a9

Please sign in to comment.