Skip to content
Permalink
Browse files

Add test for MSSQL behavior with invalid polygon geometries

Forward port of 039866d, because I am an idiot and forgot
  • Loading branch information
nyalldawson committed Oct 8, 2018
1 parent dafeaf4 commit eb40d911dfd03b0fd006629b48cb30e55d72d767
Showing with 121 additions and 0 deletions.
  1. +20 −0 tests/src/python/test_provider_mssql.py
  2. +101 −0 tests/testdata/provider/testdata_mssql.sql
@@ -267,6 +267,26 @@ def testInsertPolygonInMultiPolygon(self):
geom = [f.geometry().asWkt() for f in new_layer.getFeatures()]
self.assertEqual(geom, ['MultiPolygon (((0 0, 1 0, 1 1, 0 1, 0 0)),((10 0, 11 0, 11 1, 10 1, 10 0)))', 'MultiPolygon (((30 0, 31 0, 31 1, 30 1, 30 0)))'])

def testInvalidGeometries(self):
""" Test what happens when SQL Server is a POS and throws an exception on encountering an invalid geometry """
vl = QgsVectorLayer('%s srid=4167 type=POLYGON table="qgis_test"."invalid_polys" (ogr_geometry) sql=' %
(self.dbconn), "testinvalid", "mssql")
assert(vl.isValid())

#burn through features - don't want SQL server to trip up on the invalid ones
count = 0
for f in vl.dataProvider().getFeatures():
count += 1
self.assertEqual(count, 39)

count = 0

for f in vl.dataProvider().getFeatures(QgsFeatureRequest(QgsRectangle(173, -42, 174, -41))):
count += 1
# two invalid geometry features
self.assertEqual(count, 37)
# sorry... you get NO chance to see these features exist and repair them... because SQL server. Use PostGIS instead and live a happier life!


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

0 comments on commit eb40d91

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