Skip to content

Commit

Permalink
Use an exception-safe TableBackup class for reentrancy
Browse files Browse the repository at this point in the history
Use from testJson
  • Loading branch information
strk committed Oct 13, 2021
1 parent 820389a commit 2b8a3fd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -108,6 +108,19 @@ def restoreTable(self, schema, 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))

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

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

def getSource(self):
# create temporary table for edit tests
self.execSQLCommand(
Expand Down Expand Up @@ -1448,6 +1461,9 @@ def testJson(self):
(self.dbconn), "testjson", "postgres")
self.assertTrue(vl.isValid())

# Backup test table (will be edited)
tableBackup = self.TableBackup(self, 'qgis_test', 'json')

attrs = (
123,
1233.45,
Expand Down

0 comments on commit 2b8a3fd

Please sign in to comment.