Skip to content
Permalink
Browse files

Merge pull request #34904 from elpaso/pgraster-test-fix

Try to make PG raster test more robust
  • Loading branch information
elpaso committed Mar 6, 2020
2 parents beab5a3 + 3b6bc30 commit 1773270f69f4a97594ae7bf20af300b7270b4879
Showing with 12 additions and 12 deletions.
  1. +12 −12 tests/src/python/test_provider_postgresraster.py
@@ -66,8 +66,19 @@ def setUpClass(cls):
cls.dbconn = 'service=qgis_test'
if 'QGIS_PGTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_PGTEST_DB']
# Create test layers

cls._load_test_table('public', 'raster_tiled_3035')
cls._load_test_table('public', 'raster_3035_no_constraints')
cls._load_test_table('public', 'raster_3035_tiled_no_overviews')
cls._load_test_table('public', 'raster_3035_tiled_no_pk')
cls._load_test_table('public', 'raster_3035_tiled_composite_pk')
cls._load_test_table('public', 'raster_3035_untiled_multiple_rows')
cls._load_test_table('idro', 'cosmo_i5_snow', 'bug_34823_pg_raster')

# Fix timing issues in backend
#time.sleep(1)

# Create test layer
cls.rl = QgsRasterLayer(cls.dbconn + ' sslmode=disable key=\'rid\' srid=3035 table="public"."raster_tiled_3035" sql=', 'test', 'postgresraster')
assert cls.rl.isValid()
cls.source = cls.rl.dataProvider()
@@ -118,21 +129,18 @@ def testBlockTiled(self):
def testNoConstraintRaster(self):
"""Read unconstrained raster layer"""

self._load_test_table('public', 'raster_3035_no_constraints')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable key=\'pk\' srid=3035 table="public"."raster_3035_no_constraints" sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())

def testPkGuessing(self):
"""Read raster layer with no pkey in uri"""

self._load_test_table('public', 'raster_tiled_3035')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_tiled_3035" sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())

def testWhereCondition(self):
"""Read raster layer with where condition"""

self._load_test_table('public', 'raster_3035_tiled_no_overviews')
rl_nowhere = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_3035_tiled_no_overviews"' +
'sql=', 'test', 'postgresraster')
self.assertTrue(rl_nowhere.isValid())
@@ -162,15 +170,13 @@ def testWhereCondition(self):
def testNoPk(self):
"""Read raster with no PK"""

self._load_test_table('public', 'raster_3035_tiled_no_pk')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_3035_tiled_no_pk"' +
'sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())

def testCompositeKey(self):
"""Read raster with composite pks"""

self._load_test_table('public', 'raster_3035_tiled_composite_pk')
rl = QgsRasterLayer(self.dbconn + ' sslmode=disable srid=3035 table="public"."raster_3035_tiled_composite_pk"' +
'sql=', 'test', 'postgresraster')
self.assertTrue(rl.isValid())
@@ -235,17 +241,13 @@ def testOtherSchema(self):
"""Test that a layer in a different schema than public can be loaded
See: GH #34823"""

self._load_test_table('idro', 'cosmo_i5_snow', 'bug_34823_pg_raster')

rl = QgsRasterLayer(self.dbconn + " sslmode=disable table={table} schema={schema}".format(table='cosmo_i5_snow', schema='idro'), 'pg_layer', 'postgresraster')
self.assertTrue(rl.isValid())
self.assertTrue(compareWkt(rl.extent().asWktPolygon(), 'POLYGON((-64.79286766849691048 -77.26689086732433509, -62.18292922825105506 -77.26689086732433509, -62.18292922825105506 -74.83694818157819384, -64.79286766849691048 -74.83694818157819384, -64.79286766849691048 -77.26689086732433509))'))

def testUntiledMultipleRows(self):
"""Test multiple rasters (one per row)"""

self._load_test_table('public', 'raster_3035_untiled_multiple_rows')

rl = QgsRasterLayer(self.dbconn + " sslmode=disable table={table} schema={schema} sql=\"pk\" = 1".format(table='raster_3035_untiled_multiple_rows', schema='public'), 'pg_layer', 'postgresraster')
self.assertTrue(rl.isValid())
block = rl.dataProvider().block(1, rl.extent(), 2, 2)
@@ -267,8 +269,6 @@ def testUntiledMultipleRows(self):
def testSetSubsetString(self):
"""Test setSubsetString"""

self._load_test_table('public', 'raster_3035_untiled_multiple_rows')

rl = QgsRasterLayer(self.dbconn + " sslmode=disable table={table} schema={schema} sql=\"pk\" = 2".format(table='raster_3035_untiled_multiple_rows', schema='public'), 'pg_layer', 'postgresraster')
self.assertTrue(rl.isValid())

0 comments on commit 1773270

Please sign in to comment.
You can’t perform that action at this time.