Skip to content
Permalink
Browse files
Add ewkt tests
  • Loading branch information
m-kuhn committed Nov 19, 2021
1 parent 4ba46b8 commit ee255afb1f5af1caadc0d48479b6903c7bf0eeb5
Showing with 28 additions and 0 deletions.
  1. +28 −0 tests/src/python/test_provider_postgres.py
@@ -41,6 +41,7 @@
QgsTransactionGroup,
QgsReadWriteContext,
QgsRectangle,
QgsReferencedGeometry,
QgsDefaultValue,
QgsCoordinateReferenceSystem,
QgsProject,
@@ -3509,6 +3510,33 @@ def testExportPkGuessLogic(self):

self.assertEqual(exported_layer.fields().names(), ['id', 'name', 'author'])

def testEwkt(self):
vl = QgsVectorLayer(f'{self.dbconn} table="qgis_test"."someData" sql=', "someData", "postgres")
tg = QgsTransactionGroup()
tg.addLayer(vl)

feature = next(vl.getFeatures())
# make sure we get a QgsReferenceGeometry and not "just" a string
self.assertEqual(feature['geom'].crs().authid(), 'EPSG:4326')

vl.startEditing()

# Layer accepts a referenced geometry
feature['geom'] = QgsReferencedGeometry(QgsGeometry.fromWkt('POINT(70 70)'), QgsCoordinateReferenceSystem.fromEpsgId(4326))
self.assertTrue(vl.updateFeature(feature))

# Layer will accept null geometry
feature['geom'] = QgsReferencedGeometry()
self.assertTrue(vl.updateFeature(feature))

# Layer will not accept invalid crs
feature['geom'] = QgsReferencedGeometry(QgsGeometry.fromWkt('POINT(1 1)'), QgsCoordinateReferenceSystem())
self.assertFalse(vl.updateFeature(feature))

# EWKT strings are accepted too
feature['geom'] = 'SRID=4326;Point (71 78)'
self.assertTrue(vl.updateFeature(feature))


if __name__ == '__main__':
unittest.main()

0 comments on commit ee255af

Please sign in to comment.