RequestFactory を使う。
from django.test import Client, RequestFactory, TestCase
class HogeTestCase(TestCase):
def setUp(self):
self.user = User.objects.create_user('HogeTaro', 'taro@hoge.com', 'password')
self.client = Client()
self.client.login(username='HogeTaro', password='password')
def test_foo(self):
data = {
'name': 'FooJiro',
'email': 'jiro@foo.com',
}
factory = RequestFactory()
request = factory.post('[URL PATH]', data)
# ログインユーザ設定
request.user = self.user
参考URL