Skip to content

Commit

Permalink
Make TestPyQgsPostgresProvider.testNonPkBigintField idempotent
Browse files Browse the repository at this point in the history
References #45417
  • Loading branch information
strk committed Oct 13, 2021
1 parent 316fad9 commit 1ff8b57
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -99,6 +99,15 @@ def execSQLCommand(self, sql):
cur.close()
self.con.commit()

def backupTable(self, schema, table):
self.execSQLCommand('DROP TABLE IF EXISTS {s}.{t}_edit CASCADE'.format(s=schema, t=table))
self.execSQLCommand('CREATE TABLE {s}.{t}_edit AS SELECT * FROM {s}.{t}'.format(s=schema, t=table))

def restoreTable(self, schema, table):
self.execSQLCommand('TRUNCATE TABLE {s}.{t}'.format(s=schema, t=table))
self.execSQLCommand('INSERT INTO {s}.{t} SELECT * FROM {s}.{t}_edit'.format(s=schema, t=table))
self.execSQLCommand('DROP TABLE {s}.{t}_edit'.format(s=schema, t=table))

def getSource(self):
# create temporary table for edit tests
self.execSQLCommand(
Expand Down Expand Up @@ -646,6 +655,9 @@ def testNonPkBigintField(self):
self.assertTrue(vl.isValid())
flds = vl.fields()

# Backup test table (will be edited)
self.backupTable('qgis_test', 'bigint_pk')

# check if default values are correctly read back
f = next(vl.getFeatures(QgsFeatureRequest()))
bigint_with_default_idx = vl.fields().lookupField('bigint_attribute_def')
Expand Down Expand Up @@ -697,6 +709,9 @@ def testNonPkBigintField(self):
self.assertEqual(f['bigint_attribute'], 84)
self.assertEqual(f['bigint_attribute_def'], 42)

# Restore test table
self.restoreTable('qgis_test', 'bigint_pk')

def testPktUpdateBigintPk(self):
"""Test if we can update objects with positive, zero and negative bigint PKs."""
vl = QgsVectorLayer(
Expand Down

0 comments on commit 1ff8b57

Please sign in to comment.