Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for TopoGeometry layers visibility with and w/out permissions
Adds a "qgis_test_user" database users with the db setup script,
using an hard-coded password for connection.

This was the simplest way to make things work because the alternative
of using 'options' member in the URI is not supported by QGIS
at the moment, see #32832
  • Loading branch information
strk authored and nyalldawson committed Nov 20, 2019
1 parent 0558a5c commit 90c8301
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
28 changes: 28 additions & 0 deletions tests/src/python/test_qgsproviderconnection_postgres.py
Expand Up @@ -98,6 +98,34 @@ def test_postgis_connections(self):
self.assertEqual(srids_and_types,
[[0, 1], [0, 2], [0, 3], [0, 7], [3857, 1], [4326, 1]])

# Check TopoGeometry layers are found in vector table names

tables = conn.tables('qgis_test', QgsAbstractDatabaseProviderConnection.Vector)
table_names = self._table_names(tables)
self.assertTrue('TopoLayer1' in table_names)
self.assertTrue('geometries_table' in table_names)

# Revoke select permissions on topology.topology from qgis_test_user
conn.executeSql('REVOKE SELECT ON topology.topology FROM qgis_test_user')

# Re-connect as the qgis_test_role role
newuri = self.uri + ' user=qgis_test_user password=qgis_test_user_password'
conn = md.createConnection(newuri, {})

tables = conn.tables('qgis_test', QgsAbstractDatabaseProviderConnection.Vector)
table_names = self._table_names(tables)
self.assertFalse('TopoLayer1' in table_names)
self.assertTrue('geometries_table' in table_names)

# TODO: only revoke select permission on topology.layer, grant
# on topology.topology

# TODO: only revoke usage permission on topology, grant
# all on topology.layer and topology.topology

# TODO: only revoke select permission the actual topology
# schema associated with TopoLayer1

# error: ERROR: relation "qgis_test.raster1" does not exist
@unittest.skipIf(gdal.VersionInfo() < '2040000', 'This test requires GDAL >= 2.4.0')
def test_postgis_raster_rename(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/testdata/provider/testdata_pg.sh
Expand Up @@ -7,10 +7,12 @@ DB=${DB:-qgis_test}
SCRIPTS="
tests/testdata/provider/testdata_pg.sql
tests/testdata/provider/testdata_pg_reltests.sql
tests/testdata/provider/testdata_pg_role.sql
tests/testdata/provider/testdata_pg_vectorjoin.sql
tests/testdata/provider/testdata_pg_hstore.sql
tests/testdata/provider/testdata_pg_array.sql
tests/testdata/provider/testdata_pg_raster.sql
tests/testdata/provider/testdata_pg_topology.sql
tests/testdata/provider/testdata_pg_domain.sql
tests/testdata/provider/testdata_pg_json.sql
"
Expand Down
4 changes: 2 additions & 2 deletions tests/testdata/provider/testdata_pg_raster.sql
@@ -1,5 +1,3 @@
-- Table: qgis_test.raster1

DO $$
BEGIN
IF EXISTS ( SELECT * FROM pg_catalog.pg_available_extensions
Expand All @@ -11,6 +9,8 @@ BEGIN
END;
$$;

-- Table: qgis_test.Raster1

CREATE TABLE qgis_test."Raster1"
(
pk serial NOT NULL,
Expand Down
3 changes: 3 additions & 0 deletions tests/testdata/provider/testdata_pg_role.sql
@@ -0,0 +1,3 @@
DROP USER IF EXISTS qgis_test_user;
CREATE USER qgis_test_user PASSWORD 'qgis_test_user_password' LOGIN;

38 changes: 38 additions & 0 deletions tests/testdata/provider/testdata_pg_topology.sql
@@ -0,0 +1,38 @@
DO $$
DECLARE
layerid INTEGER;

BEGIN
IF EXISTS ( SELECT * FROM pg_catalog.pg_available_extensions
WHERE name = 'postgis_topology' )
THEN
RAISE NOTICE 'Loading postgis_topology';
CREATE EXTENSION IF NOT EXISTS postgis_topology;

-- Topology: qgis_test_Topo1

IF EXISTS ( SELECT * FROM pg_catalog.pg_namespace WHERE
nspname = 'qgis_test_Topo1' )
THEN
PERFORM topology.DropTopology('qgis_test_Topo1');
END IF;

PERFORM topology.CreateTopology('qgis_test_Topo1');

-- TopoLayer: qgis_test.TopoLayer1

DROP TABLE IF EXISTS qgis_test."TopoLayer1";
CREATE TABLE qgis_test."TopoLayer1" (id serial primary key);
layerid := topology.AddTopoGeometryColumn('qgis_test_Topo1',
'qgis_test',
'TopoLayer1',
'topogeom',
'POLYGON');
INSERT INTO qgis_test."TopoLayer1" (topogeom) SELECT
topology.toTopoGeom('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
'qgis_test_Topo1', layerid);

END IF;
END;
$$;

0 comments on commit 90c8301

Please sign in to comment.