Skip to content
Permalink
Browse files
Use an exception-safe TableBackup class for reentrancy
Use from testJson
  • Loading branch information
strk committed Oct 13, 2021
1 parent 820389a commit 2b8a3fd46e41d54121c4a151af951bcd9ffa7755
Showing with 16 additions and 0 deletions.
  1. +16 −0 tests/src/python/test_provider_postgres.py
@@ -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(
@@ -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,

0 comments on commit 2b8a3fd

Please sign in to comment.