Django 2.0 - How to deal with testing on only one database when we have several?

Django 2.0 - How to deal with testing on only one database when we have several?



First of all, I'm new to asking question here, so bear with me if I don't do it perfectly :) Here goes...



I am setting up a Django2.0 API that is going to deal with statistics. It has its own 'default' database to write stuff obviously, but I am going to need several other databases that will be read-only. This is what the settings look like for now.


DATABASES =
'default':
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dev_gpws',
'USER': 'dev_gpws_user',
'PASSWORD': 'gpws_pwd',
'HOST': 'localhost',
'PORT': '5432',
,
'other_db':
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'other_db_name',
'USER': 'other_db_user',
'PASSWORD': 'other_db_pwd',
'HOST': 'other_db_host',
'PORT': '5432',
,



When fabric deploys the project into staging, part of the routine is ./manage.py test, which leads to the following error:


./manage.py test


(gpws) dev_gpws@af968cdb7653:~/gpws/project$ ./manage.py test
Creating test database for alias 'default'...
Creating test database for alias 'other_db'...
Got an error creating the test database: ERREUR: permission denied to create database



It makes total sense considering other_db_user is a read-only user, so I would like to disable django's testing for this database. Is there a clean way to do it ? Also, this stats app is going to be linked with quite a few databases later on, so I would rather use a solution that's easy to scale.


other_db_user



Thanks in advance for any tip you will throw my way !



edit: just to clarify, I need to access the read_only databases when testing, but django shouldn't create test_databases, it should use the staging ones it is given :)





You can make test_settings.py as a settings file.
– Willem Van Onsem
Aug 26 at 9:56


test_settings.py





Furthermore looks like a perfect question! :)
– Willem Van Onsem
Aug 26 at 9:56





Hi @WillemVanOnsem, and thank you for the VERY fast answer. However, I am not sure I understand what you want me to do. Should I duplicate my settings.py into a test_settings.py and delete extra databases from there ? If so, how do I write tests that read into those read-only databases ? I just noticed my question said I wanted to disable django testing, but what I think I want is to disable is django creating a test database, I'll try and edit my question accordingly. :)
– Vincent Charles
Aug 26 at 10:00



settings.py


test_settings.py









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)