How do I populate the test database created while testing the Django test cases with the values from some other database(for ex: the Production database.)
In detail:
when I run the below command,
$ python manage.py test
a test data base is created for the testing purpose, but it doesn't have any data in it. I want the test database created to be populated with some initial values.
Thanks..
You can use dumpdata to get a file with data from your live db.
Then you can load data from a file automatically for a test (see Django tests):
from django.test import TestCase
from django.core.management import call_command
class Tests(TestCase):
@classmethod
def setUpTestData(cls):
call_command('loaddata', 'myfile', verbosity=0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With