Skip to content
Permalink
Browse files

Add test for MSSQL behavior with invalid polygon geometries

  • Loading branch information
nyalldawson committed Jun 2, 2017
1 parent 8dec70c commit 039866d4d4e86563f05649e8b8cf8aa95c46c0b7
Showing with 125 additions and 1 deletion.
  1. +22 −1 tests/src/python/test_provider_mssql.py
  2. +103 −0 tests/testdata/provider/testdata_mssql.sql
@@ -16,7 +16,7 @@

import os

from qgis.core import QgsVectorLayer, QgsFeatureRequest
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsRectangle

from qgis.PyQt.QtCore import QSettings, QDate, QTime, QDateTime, QVariant

@@ -127,5 +127,26 @@ def testDateTimeTypes(self):
self.assertEqual(f.attributes()[datetime_idx], QDateTime(
QDate(2004, 3, 4), QTime(13, 41, 52)))

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 039866d

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