Skip to content
Permalink
Browse files

More unit tests

  • Loading branch information
nyalldawson committed May 7, 2020
1 parent dce0633 commit 3994da6368b8d6d5b09db9dd5ebcff8b869f8f2b
Showing with 34 additions and 1 deletion.
  1. +34 −1 tests/src/python/test_qgsvectorlayertemporalproperties.py
@@ -15,7 +15,8 @@
from qgis.core import (QgsDateTimeRange,
QgsVectorLayerTemporalProperties,
QgsReadWriteContext,
QgsVectorLayer)
QgsVectorLayer,
QgsVectorDataProviderTemporalCapabilities)
from qgis.PyQt.QtCore import (QDateTime,
QDate,
QTime,
@@ -49,6 +50,38 @@ def testReadWrite(self):
self.assertEqual(props2.startField(), props.startField())
self.assertEqual(props2.endField(), props.endField())

def testModeFromProvider(self):
caps = QgsVectorDataProviderTemporalCapabilities()
props = QgsVectorLayerTemporalProperties()
props.setDefaultsFromDataProviderTemporalCapabilities(caps)
self.assertFalse(props.isActive())

caps.setHasTemporalCapabilities(True)
caps.setAvailableTemporalRange(QgsDateTimeRange(QDateTime(2006, 3, 11, 0, 13, 20), QDateTime(2017, 2, 14, 1, 33, 20)))
props.setDefaultsFromDataProviderTemporalCapabilities(caps)
self.assertTrue(props.isActive())
self.assertFalse(props.startField())
self.assertFalse(props.endField())
self.assertEqual(props.mode(), QgsVectorLayerTemporalProperties.ModeFixedTemporalRange)
self.assertEqual(props.fixedTemporalRange().begin(), QDateTime(2006, 3, 11, 0, 13, 20))
self.assertEqual(props.fixedTemporalRange().end(), QDateTime(2017, 2, 14, 1, 33, 20))

caps.setStartField('start_field')
caps.setMode(QgsVectorDataProviderTemporalCapabilities.ProviderStoresFeatureDateTimeInstantInField)
props.setDefaultsFromDataProviderTemporalCapabilities(caps)
self.assertTrue(props.isActive())
self.assertEqual(props.startField(), 'start_field')
self.assertFalse(props.endField())
self.assertEqual(props.mode(), QgsVectorLayerTemporalProperties.ModeFeatureDateTimeInstantFromField)

caps.setEndField('end_field')
caps.setMode(QgsVectorDataProviderTemporalCapabilities.ProviderStoresFeatureDateTimeStartAndEndInSeparateFields)
props.setDefaultsFromDataProviderTemporalCapabilities(caps)
self.assertTrue(props.isActive())
self.assertEqual(props.startField(), 'start_field')
self.assertEqual(props.endField(), 'end_field')
self.assertEqual(props.mode(), QgsVectorLayerTemporalProperties.ModeFeatureDateTimeStartAndEndFromFields)

def testFixedRangeMode(self):
props = QgsVectorLayerTemporalProperties(enabled=True)
props.setMode(QgsVectorLayerTemporalProperties.ModeFixedTemporalRange)

0 comments on commit 3994da6

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