I am trying to test a custom permissions class using APIRequestFactory to fabricate a request. The custom permissions object checks the request body for an OTP using request.data, a convenience property added by DRF Request objects. However this fails because APIRequestFactory directly returns the WSGIRequest object returned by Django's RequestFactory.
master branch of Django REST framework. api_rf = APIRequestFactory()
request = api_rf.post('/some/url', {})
request.data.get('foo')
None
AttributeError: 'WSGIRequest' object has no attribute 'data'
This is a duplicate of #3608 (closed).
You can probably achieve what you want by following https://github.com/tomchristie/django-rest-framework/issues/3608#issuecomment-154427523.
So it is. Thanks for the heads-up 馃憤 .
Aside: I have warmed to the idea of ensuring that this returns a fully fledged Request instance, and having views be able to handle either, so this might come up in the future.
try
request.DATA
(caps)
Most helpful comment
Aside: I have warmed to the idea of ensuring that this returns a fully fledged
Requestinstance, and having views be able to handle either, so this might come up in the future.