尝试在 Python 单元测试中设置请求正文(request.body):
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)
但是它报错了:
self.request.body = json.dumps(self.post_data)
AttributeError: can't set attribute
有人能帮我修复这个问题吗?