Skip to content

Commit

Permalink
Add ewkt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 19, 2021
1 parent 4ba46b8 commit ee255af
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -41,6 +41,7 @@
QgsTransactionGroup,
QgsReadWriteContext,
QgsRectangle,
QgsReferencedGeometry,
QgsDefaultValue,
QgsCoordinateReferenceSystem,
QgsProject,
Expand Down Expand Up @@ -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.