trying to set request.body in python unit test as
self.factory = RequestFactory()
self.request = self.factory.get(reverse('get_associations'))
self.request.user = self.auth_user
self.request.body = json.dumps(self.post_data)
but it gives error:
self.request.body = json.dumps(self.post_data)
AttributeError: can't set attribute
can anybody help me to fix this?
Based on this answer, try this:
self.request = self.factory.get(reverse('get_associations'),
data=json.dumps(self.post_data),
content_type='application/json')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With