Lets say I have this APIView
class Dummy(APIView):
def get(self, request):
return Response(data=request.query_params.get('uuid'))
To test it, I need to create a request object to pass into the get function
def test_dummy(self):
from rest_framework.test import APIRequestFactory
factory = APIRequestFactory()
request = factory.get('/?uuid=abcd')
DummyView().get(request)
It complains about AttributeError: 'WSGIRequest' object has no attribute 'query_params'
Having a closer look, the factory creates a WSGIRequest instance instead of a DRF version <class 'rest_framework.request.Request'>.
>>> from rest_framework.test import APIRequestFactory
>>> factory = APIRequestFactory()
>>> request = factory.get('/')
>>> request.__class__
<class 'django.core.handlers.wsgi.WSGIRequest'>