Skip to content

Commit 913ec16

Browse files
committed
Fixed schema generation.
Refactored the auto schema allows filters test. Removed an unused import. Removed another unused import.
1 parent a3df1c1 commit 913ec16

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

rest_framework/schemas/inspectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def _allows_filters(self, path, method):
368368
if hasattr(self.view, 'action'):
369369
return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"]
370370

371-
return method.lower in ["get", "put", "patch", "delete"]
371+
return method.lower() in ["get", "put", "patch", "delete"]
372372

373373
def get_filter_fields(self, path, method):
374374
if not self._allows_filters(path, method):

tests/test_schemas.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,51 @@ def custom_action(self, request, pk):
951951

952952
assert inspector.should_include_endpoint(path, callback)
953953
assert inspector.get_allowed_methods(callback) == ["GET"]
954+
955+
956+
class TestAutoSchemaAllowsFilters(object):
957+
class MockAPIView(APIView):
958+
filter_backends = [filters.OrderingFilter]
959+
960+
def _test(self, method):
961+
view = self.MockAPIView()
962+
fields = view.schema.get_filter_fields('', method)
963+
field_names = [f.name for f in fields]
964+
965+
return 'ordering' in field_names
966+
967+
def test_get(self):
968+
assert self._test('get')
969+
970+
def test_GET(self):
971+
assert self._test('GET')
972+
973+
def test_put(self):
974+
assert self._test('put')
975+
976+
def test_PUT(self):
977+
assert self._test('PUT')
978+
979+
def test_patch(self):
980+
assert self._test('patch')
981+
982+
def test_PATCH(self):
983+
assert self._test('PATCH')
984+
985+
def test_delete(self):
986+
assert self._test('delete')
987+
988+
def test_DELETE(self):
989+
assert self._test('DELETE')
990+
991+
def test_post(self):
992+
assert not self._test('post')
993+
994+
def test_POST(self):
995+
assert not self._test('POST')
996+
997+
def test_foo(self):
998+
assert not self._test('foo')
999+
1000+
def test_FOO(self):
1001+
assert not self._test('FOO')

0 commit comments

Comments
 (0)