Skip to content

Fixed schema generation for filter backends #5613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest_framework/schemas/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _allows_filters(self, path, method):
if hasattr(self.view, 'action'):
return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"]

return method.lower in ["get", "put", "patch", "delete"]
return method.lower() in ["get", "put", "patch", "delete"]

def get_filter_fields(self, path, method):
if not self._allows_filters(path, method):
Expand Down
48 changes: 48 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,3 +951,51 @@ def custom_action(self, request, pk):

assert inspector.should_include_endpoint(path, callback)
assert inspector.get_allowed_methods(callback) == ["GET"]


class TestAutoSchemaAllowsFilters(object):
class MockAPIView(APIView):
filter_backends = [filters.OrderingFilter]

def _test(self, method):
view = self.MockAPIView()
fields = view.schema.get_filter_fields('', method)
field_names = [f.name for f in fields]

return 'ordering' in field_names

def test_get(self):
assert self._test('get')

def test_GET(self):
assert self._test('GET')

def test_put(self):
assert self._test('put')

def test_PUT(self):
assert self._test('PUT')

def test_patch(self):
assert self._test('patch')

def test_PATCH(self):
assert self._test('PATCH')

def test_delete(self):
assert self._test('delete')

def test_DELETE(self):
assert self._test('DELETE')

def test_post(self):
assert not self._test('post')

def test_POST(self):
assert not self._test('POST')

def test_foo(self):
assert not self._test('foo')

def test_FOO(self):
assert not self._test('FOO')