Skip to content

Commit

Permalink
Make TestPyQgsPostgresProvider.testGeneratedFields idempotent
Browse files Browse the repository at this point in the history
References #45417
  • Loading branch information
strk committed Oct 13, 2021
1 parent 1295cb1 commit 316fad9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -531,6 +531,10 @@ def testGeneratedFields(self):
if pgversion < 120000:
return

# Backup test table (will be edited)
self.execSQLCommand('DROP TABLE IF EXISTS qgis_test.test_gen_col_edit CASCADE')
self.execSQLCommand('CREATE TABLE qgis_test.test_gen_col_edit AS SELECT id,name,geom FROM qgis_test.test_gen_col')

# Geometry columns
vl = QgsVectorLayer('{} table="qgis_test"."{}" (geom) srid=4326 type=POLYGON key="id" sql='.format(self.dbconn, "test_gen_col"), "test_gen_col", "postgres")
self.assertTrue(vl.isValid())
Expand Down Expand Up @@ -628,6 +632,11 @@ def testGeneratedFields(self):
assert compareWkt(generated_geometry, expected_geometry), "Geometry mismatch! Expected:\n{}\nGot:\n{}\n".format(expected_geometry, generated_geometry)
self.assertEqual(f4['poly_area'], expected_area)

# Restore test table (after editing it)
self.execSQLCommand('TRUNCATE TABLE qgis_test.test_gen_col')
self.execSQLCommand('INSERT INTO qgis_test.test_gen_col(id,name,geom) SELECT id,name,geom FROM qgis_test.test_gen_col_edit')
self.execSQLCommand('DROP TABLE qgis_test.test_gen_col_edit')

def testNonPkBigintField(self):
"""Test if we can correctly insert, read and change attributes(fields) of type bigint and which are not PKs."""
vl = QgsVectorLayer(
Expand Down

0 comments on commit 316fad9

Please sign in to comment.