mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Fixed schema generation for filter backends (#5613)
This commit is contained in:
		
							parent
							
								
									a3df1c1199
								
							
						
					
					
						commit
						134a6f66f9
					
				| 
						 | 
					@ -368,7 +368,7 @@ class AutoSchema(ViewInspector):
 | 
				
			||||||
        if hasattr(self.view, 'action'):
 | 
					        if hasattr(self.view, 'action'):
 | 
				
			||||||
            return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"]
 | 
					            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):
 | 
					    def get_filter_fields(self, path, method):
 | 
				
			||||||
        if not self._allows_filters(path, method):
 | 
					        if not self._allows_filters(path, method):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -951,3 +951,51 @@ def test_head_and_options_methods_are_excluded():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert inspector.should_include_endpoint(path, callback)
 | 
					    assert inspector.should_include_endpoint(path, callback)
 | 
				
			||||||
    assert inspector.get_allowed_methods(callback) == ["GET"]
 | 
					    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')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user