For recording.
I created my own command in the commands directory and tried to do the same as the following command from within the test.
$ python manage.py create_initial_data
I was wondering if I would run commands in the shell when setting up the test, but Django was well supported here.
Embed the call_command
function in the target script.
from django.test import TestCase, Client
from django.core.management import call_command
class TestSendEmailView(TestCase):
def setUp(self):
self.client = Client()
call_command('create_initial_data') #here
def test_success(self):
response = self.client.get('/emails/')
self.assertEqual(response.status_code, 200)
This will do the same thing as python manage.py create_initial_data
.
Recommended Posts