Skip to content
Permalink
Browse files

[postgres][test] Assert NULL insert behavior

0 != '' != NULL
  • Loading branch information
m-kuhn committed Oct 28, 2017
1 parent 3b0b82c commit 76746e7d5e97f0bcd07179e10e1d01c87c5a030e
Showing with 35 additions and 0 deletions.
  1. +35 −0 tests/src/python/test_provider_postgres.py
@@ -303,6 +303,41 @@ def testPktMapInsert(self):
self.assertNotEqual(f[0]['obj_id'], NULL, f[0].attributes())
vl.deleteFeatures([f[0].id()])

def testNull(self):
"""
Asserts that 0, '' and NULL are treated as different values on insert
"""
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'gid\' table="qgis_test"."constraints" sql=', 'test1', 'postgres')
self.assertTrue(vl.isValid())
QgsProject.instance().addMapLayer(vl)
tg = QgsTransactionGroup()
tg.addLayer(vl)
vl.startEditing()

def onError(message):
"""We should not get here. If we do, fail and say why"""
self.assertFalse(True, message)

vl.raiseError.connect(onError)

f = QgsFeature(vl.fields())
f['gid'] = 100
f['val'] = 0
f['name'] = ''
self.assertTrue(vl.addFeature(f))
feature = next(vl.getFeatures('"gid" = 100'))
self.assertEqual(f['val'], feature['val'])
self.assertEqual(f['name'], feature['name'])

f = QgsFeature(vl.fields())
f['gid'] = 101
f['val'] = NULL
f['name'] = NULL
vl.addFeature(f)
feature = next(vl.getFeatures('"gid" = 101'))
self.assertEqual(f['val'], feature['val'])
self.assertEqual(f['name'], feature['name'])

def testNestedInsert(self):
tg = QgsTransactionGroup()
tg.addLayer(self.vl)

0 comments on commit 76746e7

Please sign in to comment.
You can’t perform that action at this time.