-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Problem
Django has a mechanism for creating a test database when running unitary tests, cf. https://docs.djangoproject.com/en/4.2/topics/testing/overview/#the-test-database
Problems:
- 1. This test database, named
test_<your database name>
, is created with your default database USER/PASSWORD credentials, and your USER does not have the CREATEDB authorization - 2. If you use postgis, the extension will have to be activated but your user will not have the right to CREATE EXTENSION postgis
- 3. Because of the PostgreSQL Host-Based Authentication Configuration (file
~/var/pgsql/pg_hba.conf
) which allow only the "sameuser" (i.e a user name equal ta dabasename) to connect to database (see below), our user cannot connect to the test database.
local all all trust
host sameuser all 0.0.0/0
host sameuser all ::1/128
Workaround solution
- In your plugin's sql directory, add an sql script
alter_role_django_test_compatibility.sql
with content:
--connect to database "plugin_<plugin_name>" as user "metwork"
\c plugin_<plugin_name> metwork;
--give role CREATEDB, for django testing purpose
ALTER ROLE plugin_<plugin_name> CREATEDB;
--give role SUPERUSER, for creating POSTGIS extension
ALTER ROLE plugin_<plugin_name> SUPERUSER;
It will give the rights to create the test database and to activate the extension postgis for your test database.
This is not well as we give the superuser role....
- In you plugin's postinstall script, add:
#!/bin/bash
# add postgresql authorizations, for django testing purpose
echo "host all plugin_<plugin_name> 0.0.0.0/0 md5" >> ~/var/pgsql/pg_hba.conf
echo "host all plugin_<plugin_name> ::1/128 md5" >> ~/var/pgsql/pg_hba.conf
echo "Authorizations added. You must restart mfbase."
exit 0
It will allow your database user to connect to the test database.
Perennial solution
To Be Determined
Metadata
Metadata
Assignees
Labels
No labels