12๐
I solved this by changing the DATABASES.TEST
definition. I added the TEST['MIRROR'] = 'default'
to the mdm_db
database entry.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=1521)))(CONNECT_DATA=(SID=%s)))'
% (get_env_variable('LIMS_MIGRATION_HOST'), get_env_variable('LIMS_MIGRATION_SID')),
'USER': 'LIMS_MIGRATION',
'PASSWORD': get_env_variable('LIMS_MIGRATION_PASSWORD'),
},
'mdm_db': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=GB3P)(PORT=1521)))'
'(CONNECT_DATA=(SID=GB3P)))',
'USER': 'MDM',
'PASSWORD': get_env_variable('MDM_DB_PASSWORD'),
'TEST': {
'MIRROR': 'default', # Added this setting
}
},
}
According to the documentation this option can be abused to skip database creation:
However, the replica database has been configured as a test mirror
(using the MIRROR test setting), indicating that under testing,
replica should be treated as a mirror of default.When the test environment is configured, a test version of replica
will not be created. Instead the connection to replica will be
redirected to point at default.
Running my tests now skips creation of the second database.
Thanks for all the input!!
3๐
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!
- [Django]-Heroku, postgreSQL, django, comments, tastypie: No operator matches the given name and argument type(s). You might need to add explicit type casts
- [Django]-Django Admin app or roll my own?
- [Django]-Switching to PostgreSQL fails loading datadump
0๐
You could try to mock out the connection to the second database using python mocks?https://pypi.python.org/pypi/mock โ now part of the stdlib in python 3.
- [Django]-Django migration fails with "__fake__.DoesNotExist: Permission matching query does not exist."
- [Django]-Django filter JSONField list of dicts
- [Django]-Remove pk field from django serialized objects