I have a django application that uses 2 database connections:
Use the --settings
flag with the test command. In the path.to.test.py module, a la python manage.py test --settings=app.settings.test
. There is no need to muck around with routes, just make sure that you invoke the tests with the settings flag whenever and where ever you call it.
In app.settings.test.py, redefine your DATABASES datastructure:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '',
'USER': '',
'PASSWORD': '',
},
'mdm_db': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '',
'USER': '',
'PASSWORD': '',
},
}
This allows you to use a separate database when running tests. Additionally, if you use sqlite3 as your engine, you'll find that tests run very fast as the database is in memory.
Using sqlite3 databases for testing means that even hundreds of tests can be run within seconds. As a result, you can run your tests very frequently. I typically map a key to save my work and run my tests with one action:
map ,t :up\|!python manage.py test --settings=app.settings.test
Hope that is is helpful!