Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 25, 2017
1 parent 32ff78b commit 385655f
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/src/python/test_provider_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
QgsReadWriteContext,
QgsRectangle,
QgsDefaultValue,
QgsDataSourceUri
QgsDataSourceUri,
QgsProject
)
from qgis.gui import QgsGui
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QObject
Expand Down Expand Up @@ -312,6 +313,54 @@ def testNestedInsert(self):
self.vl.addFeature(f) # Should not deadlock during an active iteration
f = next(it)

def testTransactionNotDirty(self):
# create a vector ayer based on postgres
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POLYGON table="qgis_test"."some_poly_data" (geom) sql=', 'test', 'postgres')
self.assertTrue(vl.isValid())

# prepare a project with transactions enabled
p = QgsProject()
p.setAutoTransaction(True)
p.addMapLayers([vl])
vl.startEditing()

# check that the feature used for testing is ok
ft0 = vl.getFeatures('pk=1')
f = QgsFeature()
self.assertTrue(ft0.nextFeature(f))

# update the data within the transaction
tr = vl.dataProvider().transaction()
sql = "update qgis_test.some_poly_data set pk=33 where pk=1"
self.assertTrue(tr.executeSql(sql, True)[0])

# check that the pk of the feature has been changed
ft = vl.getFeatures('pk=1')
self.assertFalse(ft.nextFeature(f))

ft = vl.getFeatures('pk=33')
self.assertTrue(ft.nextFeature(f))

# underlying data has been modified but the layer is not tagged as
# modified
self.assertTrue(vl.isModified())

# undo sql query
vl.undoStack().undo()

# check that the original feature with pk is back
ft0 = vl.getFeatures('pk=1')
self.assertTrue(ft0.nextFeature(f))

# redo
vl.undoStack().redo()

# check that the pk of the feature has been changed
ft1 = vl.getFeatures('pk=1')
self.assertFalse(ft1.nextFeature(f))

p.setAutoTransaction(False)

def testDomainTypes(self):
"""Test that domain types are correctly mapped"""

Expand Down

0 comments on commit 385655f

Please sign in to comment.