File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 11
22from rest_framework .test import APITestCase , APIRequestFactory
3+ from rest_framework_filters import FilterSet
34
45from .testapp import models , views
56
@@ -58,3 +59,25 @@ class SimpleViewSet(views.FilterFieldsUserViewSet):
5859 <button type="submit" class="btn btn-primary">Submit</button>
5960 </form>
6061 """ )
62+
63+ def test_request_obj_is_passed (self ):
64+ """
65+ Ensure that the request object is passed from the backend to the filterset.
66+ See: https://github.com/philipn/django-rest-framework-filters/issues/149
67+ """
68+ class RequestCheck (FilterSet ):
69+ def __init__ (self , * args , ** kwargs ):
70+ super (RequestCheck , self ).__init__ (* args , ** kwargs )
71+ assert self .request is not None
72+
73+ class Meta :
74+ model = models .User
75+ fields = ['username' ]
76+
77+ class ViewSet (views .FilterFieldsUserViewSet ):
78+ filter_class = RequestCheck
79+
80+ view = ViewSet (action_map = {})
81+ backend = view .filter_backends [0 ]
82+ request = view .initialize_request (factory .get ('/' ))
83+ backend ().filter_queryset (request , view .get_queryset (), view )
You can’t perform that action at this time.
0 commit comments