python - Running Django management command from tests? -
i have django management command create materialized views on database, runs follows (i store database login details in environment variables):
python manage.py create_db_matviews $db_name $db_user $db_pass
the management command code looks 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 want run management command inside tests, materialized views created on test data. not work:
def setupmodule(): # load fixtures, then... management.call_command('create_db_matviews', ['test', 'test', 'test'], verbosity=0)
it fails follows:
.... db_user = args[1] indexerror: tuple index out of range
how can supply arguments management script in way wants?
also, credentials should use access test database?
it fails because in tuple of args set 1 argument, list of 3 values. should use:
management.call_command('create_db_matviews', 'test', 'test', 'test', verbosity=0)
*agrs
pythons way send multiple parameters , of them send tuple. send (['test', 'test', 'test', ],)
args[0]
['test', 'test', 'test', ]
, not 'test'
Comments
Post a Comment