I have a Django management command to create materialized views on my database, that runs as follows (I store my database login details in environment variables):
python manage.py create_db_matviews $DB_NAME $DB_USER $DB_PASS
The management command code looks like this:
class Command(BaseCommand):
def handle(self, *args, **options):
db_name = args[0]
db_user = args[1]
db_pass = args[2]
self.conn = psycopg2.connect(database=db_name, user=db_user,
password=db_pass)
Now I want to run the management command from inside my tests, so that the materialized views get created on my test data. However this does not work:
def setUpModule():
# load fixtures, then...
management.call_command('create_db_matviews',
['test', 'test', 'test'], verbosity=0)
It fails as follows:
....
db_user = args[1]
IndexError: tuple index out of range
How can I supply arguments to the management script in the way that it wants?
Also, what credentials should I use to get access to the test database?