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

Viewed 265

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:

(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.

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 :)

0 Answers
Related