I work in Django 1.8. I have a Django management team to create materialized views in my database as follows:
python manage.py create_db_matviews $DB_NAME $DB_USER $DB_PASS
Now I want to run a management command from my tests so that I can test this command. (My actual database is extremely large, and the management team is very slow, so I would like to test it on test data, not real data.)
However, calling the management command from my test file does not work - not surprising, since I have no idea which credentials to use:
def setUpModule():
management.call_command('loaddata', 'frontend/fixtures/mydata.json',
verbosity=0)
management.call_command('create_db_matviews',
'default', 'default', 'randomguess',
verbosity=0)
It does not work as follows:
Creating test database for alias 'default' ('test_prescribing')...
... running migrations...
======================================================================
ERROR: setUpModule (frontend.tests.test_api_views)
Traceback (most recent call last):
File "/Users/.../tests/test_api_views.py", line 23, in setUpModule
verbosity=0)
File "/Users/.../.virtualenvs/openprescribing/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
return klass.execute(*args, **defaults)
File "/Users/.../.virtualenvs/openprescribing/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/.../frontend/management/commands/create_indexes_and_matviews.py", line 19, in handle
password=db_pass)
File "/Users/.../.virtualenvs/openprescribing/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: FATAL: role "default" does not exist
What credentials should I use to access the test database?