Skip to content

Commit

Permalink
add testcase to #950. ensure raw schema dict remains unmodified
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Mar 1, 2023
1 parent 1c00668 commit 71038e9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/contrib/test_django_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,37 @@ def retrieve(self, request, *args, **kwargs):
'explode': False,
'style': 'form'
}


@pytest.mark.contrib('django_filter')
def test_filters_raw_schema_decoration_isolation(no_warnings):
from django_filters import FilterSet
from django_filters.rest_framework import DjangoFilterBackend

class SimpleFilterSet(FilterSet):
filter_field = NumberFilter(method='filter_method')

@extend_schema_field({'description': 'raw schema', 'type': 'integer'})
def filter_method(self, queryset, name, value):
pass # pragma: no cover

class Meta:
model = Product
fields = []

class XViewset(viewsets.GenericViewSet):
queryset = Product.objects.all()
serializer_class = SimpleSerializer
filterset_class = SimpleFilterSet
filter_backends = [DjangoFilterBackend]

def list(self, request, *args, **kwargs):
pass # pragma: no cover

expected = [
{'in': 'query', 'name': 'filter_field', 'schema': {'type': 'integer'}, 'description': 'raw schema'}
]
schema = generate_schema('/x', XViewset)
assert schema['paths']['/x/']['get']['parameters'] == expected
schema = generate_schema('/x', XViewset)
assert schema['paths']['/x/']['get']['parameters'] == expected

0 comments on commit 71038e9

Please sign in to comment.