Skip to content
Permalink
Browse files

Update tests for defaultValue/Clause

  • Loading branch information
elpaso committed Jan 28, 2020
1 parent 171c522 commit be63036249b87ecb2ed2d26d75ac21a6d228f6fe
Showing with 9 additions and 3 deletions.
  1. +7 −1 tests/src/python/test_provider_postgres.py
  2. +2 −2 tests/src/python/test_provider_spatialite.py
@@ -1449,12 +1449,18 @@ def testDefaultValuesAndClauses(self):
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable table="public"."test_table_default_values" sql=', 'test', 'postgres')
self.assertTrue(vl.isValid())

dp = vl.dataProvider()

# Clean the table
dp.deleteFeatures(dp.allFeatureIds())

# Save it for the test
now = datetime.now()

# Test default values
dp = vl.dataProvider()
dp.setProviderProperty(QgsDataProvider.EvaluateDefaultValues, 1)
# FIXME: spatialite provider (and OGR) return a NULL here and the following passes
# self.assertTrue(dp.defaultValue(0).isNull())
self.assertIsNotNone(dp.defaultValue(0))
self.assertIsNone(dp.defaultValue(1))
self.assertTrue(dp.defaultValue(2).startswith(now.strftime('%Y-%m-%d')))
@@ -1178,7 +1178,7 @@ def testSpatialiteDefaultValues(self):
# simple table with primary key
sql = """
CREATE TABLE test_table_default_values (
id integer primary key autoincrement,
`id` integer primary key autoincrement,
comment text,
created_at_01 text DEFAULT (datetime('now','localtime')),
created_at_02 text DEFAULT CURRENT_TIMESTAMP,
@@ -1207,7 +1207,7 @@ def testSpatialiteDefaultValues(self):
self.assertEqual(dp.defaultValue(4), 123)
self.assertEqual(dp.defaultValue(5), 'My default')

self.assertEqual(dp.defaultValueClause(0), '')
self.assertEqual(dp.defaultValueClause(0), 'Autogenerate')
self.assertEqual(dp.defaultValueClause(1), '')
self.assertEqual(dp.defaultValueClause(2), "datetime('now','localtime')")
self.assertEqual(dp.defaultValueClause(3), "CURRENT_TIMESTAMP")

0 comments on commit be63036

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