django.test.Client を使う。
from django.test import Client, 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',
}
response = self.client.post('[URL_Path]', data)
self.assertEqual(200, response.status_code)
参考URL
- https://docs.djangoproject.com/ja/2.1/topics/testing/tools/