Fixed schema generation for filter backends (#5613)

This commit is contained in:
Michał Bielawski 2017-11-22 05:11:59 +00:00 committed by Ryan P Kilby
parent a3df1c1199
commit 134a6f66f9
2 changed files with 49 additions and 1 deletions

View File

@ -368,7 +368,7 @@ class AutoSchema(ViewInspector):
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):

View File

@ -951,3 +951,51 @@ def test_head_and_options_methods_are_excluded():
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')