You can use the mockery. Some examples are available here and in the docs here.
Update
Kit, I think it really depends on your test case. But in general, you should not directly use raw_post_data. Instead, it should be fixed, as in the example below:
from mock import Mock, MagicMock class SomeTestCase(TestCase): def testRawPostData(self): ... request = Mock(spec=request) request.raw_post_data = 'myrawdata' print request.raw_post_data
source share