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:
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
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:
test_<your database name>, is created with your default database USER/PASSWORD credentials, and your USER does not have the CREATEDB authorization~/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.Workaround solution
alter_role_django_test_compatibility.sqlwith content: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....
It will allow your database user to connect to the test database.
Perennial solution
To Be Determined