POST document with Django RequestFactory instead of form data

I've tried Jay's solution and didn't work, but after some reseach, this did (Django 2.1.2)

factory = RequestFactory()    
request = factory.post('/post/url/')
request.data = {'id': 1}

RequestFactory has built-in support for JSON payloads. You don't need to dump your data first. But you should be passing the content-type to post, not to the instantiation.

factory = RequestFactory()
data = {'message':'A test message'}
request = factory.post('/a/test/path/', data, content_type='application/json')