Setting up Django / postgres to create a database to run tests

My unittests extend from django.test.TestCase. Using the SQLite3 backend, they work fine.

I want to run them using the PostgreSQL backend, and the first thing the tests do is try to create a test database. This fails because django is not allowed to do this. I want to configure PostgreSQL / django to allow this operation, but I cannot find documentation on how to do this.

These are the settings used to connect to the database ( settings.py):

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'myppasss',
        'HOST': 'localhost',
        'PORT': '',
    }
}

When starting the django application, I always have a pre-created database and user, so django can connect.

I have two questions:

  • , , unit test? , , django , ( ) .
  • ? (TEST DATABASES), Oracle .
+4
1

Django , settings.py , ( test_mydb mydb).

django psql. . .

=> ALTER USER myuser CREATEDB;

, , django test_mydb.

+4

Source: https://habr.com/ru/post/1612374/


All Articles