Skip to content

Commit

Permalink
Do not hard-code database connection parameters
Browse files Browse the repository at this point in the history
Rely on libpq defaults instead (overridable via environment)
  • Loading branch information
Sandro Santilli committed Feb 15, 2016
1 parent 942c5e5 commit ab580fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions tests/README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ Make sure that you have enabled building of postgres test in CMake.
To test the postgres provider you will need to have a database available to To test the postgres provider you will need to have a database available to
which the postgres provider can connect. The server will need to have postgis which the postgres provider can connect. The server will need to have postgis
support enabled. support enabled.
By default the test uses the following connection options:
dbname='qgis_test' By default the test uses the following connection string:
host=localhost
port=5432 dbname=qgis_test
user='postgres'
password='postgres'


If this does not match your setup you can set the environment variable If this does not match your setup you can set the environment variable
QGIS_PGTEST_DB to the desired connection string. `QGIS_PGTEST_DB` to the desired connection string, or you can rely
on standard libpq environment variables to tweak host, port user and
password (PGHOST, PGPORT, PGUSER, PGPASSWORD).


Please note that the database needs to be initialized using the sql-script Please note that the database needs to be initialized using the sql-script
tests/testdata/provider/testdata.sql
It takes care of activating postgis for the test database and tests/testdata/provider/testdata_pg*.sql
creates some tables containing test data.
They take care of activating postgis for the test database and
create some tables containing test data.
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_postgres.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Run before all tests""" """Run before all tests"""
cls.dbconn = u'dbname=\'qgis_test\' host=localhost port=5432 user=\'postgres\' password=\'postgres\'' cls.dbconn = u'dbname=\'qgis_test\''
if 'QGIS_PGTEST_DB' in os.environ: if 'QGIS_PGTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_PGTEST_DB'] cls.dbconn = os.environ['QGIS_PGTEST_DB']
# Create test layers # Create test layers
Expand Down

0 comments on commit ab580fb

Please sign in to comment.