Skip to content

Commit

Permalink
Update WFS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 19, 2017
1 parent 6508a5d commit 6c4a8a2
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tests/src/python/providertestbase.py
Expand Up @@ -298,9 +298,10 @@ def testExtent(self):
# with only one point
subset = self.getSubsetString3()
self.source.setSubsetString(subset)
self.assertEqual(self.source.featureCount(), 1)
count = self.source.featureCount()
provider_extent = self.source.extent()
self.source.setSubsetString(None)
self.assertEqual(count, 1)
self.assertAlmostEqual(provider_extent.xMinimum(), -68.2, 3)
self.assertAlmostEqual(provider_extent.xMaximum(), -68.2, 3)
self.assertAlmostEqual(provider_extent.yMinimum(), 70.8, 3)
Expand All @@ -309,9 +310,10 @@ def testExtent(self):
# with no points
subset = self.getSubsetStringNoMatching()
self.source.setSubsetString(subset)
self.assertEqual(self.source.featureCount(), 0)
count = self.source.featureCount()
provider_extent = self.source.extent()
self.source.setSubsetString(None)
self.assertEqual(count, 0)
self.assertTrue(provider_extent.isNull())

def testUnique(self):
Expand Down Expand Up @@ -354,6 +356,22 @@ def testFeatureCount(self):
self.assertEqual(count, 3)
self.assertEqual(self.source.featureCount(), 5)

# one matching records
subset = self.getSubsetString3()
self.source.setSubsetString(subset)
count = self.source.featureCount()
self.source.setSubsetString(None)
self.assertEqual(count, 1)
self.assertEqual(self.source.featureCount(), 5)

# no matching records
subset = self.getSubsetStringNoMatching()
self.source.setSubsetString(subset)
count = self.source.featureCount()
self.source.setSubsetString(None)
self.assertEqual(count, 0)
self.assertEqual(self.source.featureCount(), 5)

def testGetFeaturesNoGeometry(self):
""" Test that no geometry is present when fetching features without geometry"""

Expand Down
80 changes: 80 additions & 0 deletions tests/src/python/test_provider_wfs.py
Expand Up @@ -338,6 +338,75 @@ def setUpClass(cls):
</wfs:member>
</wfs:FeatureCollection>""".encode('UTF-8'))

with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&FILTER=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">
<fes:PropertyIsEqualTo>
<fes:ValueReference>name</fes:ValueReference>
<fes:Literal>Apple</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter>
&RESULTTYPE=hits"""), 'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
numberMatched="1" numberReturned="0" timeStamp="2016-03-25T14:51:48.998Z">
</wfs:FeatureCollection>""".encode('UTF-8'))

with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::4326&FILTER=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">
<fes:PropertyIsEqualTo>
<fes:ValueReference>name</fes:ValueReference>
<fes:Literal>Apple</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter>
"""), 'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:my="http://my"
numberMatched="1" numberReturned="1" timeStamp="2016-03-25T14:51:48.998Z">
<wfs:member>
<my:typename gml:id="typename.1">
<gml:boundedBy><gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326"><gml:lowerCorner>70.8 -68.2</gml:lowerCorner><gml:upperCorner>70.8 -68.2</gml:upperCorner></gml:Envelope></gml:boundedBy>
<my:geometryProperty><gml:Point srsName="urn:ogc:def:crs:EPSG::4326" gml:id="typename.geom.1"><gml:pos>70.8 -68.2</gml:pos></gml:Point></my:geometryProperty>
<my:pk>2</my:pk>
<my:cnt>200</my:cnt>
<my:name>Apple</my:name>
<my:name2>Apple</my:name2>
<my:num_char>2</my:num_char>
</my:typename>
</wfs:member>
</wfs:FeatureCollection>""".encode('UTF-8'))

with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&FILTER=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">
<fes:PropertyIsEqualTo>
<fes:ValueReference>name</fes:ValueReference>
<fes:Literal>AppleBearOrangePear</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter>
&RESULTTYPE=hits"""), 'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
numberMatched="0" numberReturned="0" timeStamp="2016-03-25T14:51:48.998Z">
</wfs:FeatureCollection>""".encode('UTF-8'))

with open(sanitize(endpoint, """?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my:typename&SRSNAME=urn:ogc:def:crs:EPSG::4326&FILTER=<fes:Filter xmlns:fes="http://www.opengis.net/fes/2.0">
<fes:PropertyIsEqualTo>
<fes:ValueReference>name</fes:ValueReference>
<fes:Literal>AppleBearOrangePear</fes:Literal>
</fes:PropertyIsEqualTo>
</fes:Filter>
"""), 'wb') as f:
f.write("""
<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:my="http://my"
numberMatched="0" numberReturned="0" timeStamp="2016-03-25T14:51:48.998Z">
</wfs:FeatureCollection>""".encode('UTF-8'))

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
Expand Down Expand Up @@ -2630,6 +2699,17 @@ def testGetFeatureWithNamespaces(self):
values = [f['intfield'] for f in vl.getFeatures()]
self.assertEqual(values, [1])

def testExtent(self):
# can't run the base provider test suite here - wfs extent handling is different
# to other providers
reference = QgsGeometry.fromRect(
QgsRectangle(-71.123, 66.33, -65.32, 78.3))
provider_extent = self.source.extent()
self.assertAlmostEqual(provider_extent.xMinimum(), -71.123, 3)
self.assertAlmostEqual(provider_extent.xMaximum(), -65.32, 3)
self.assertAlmostEqual(provider_extent.yMinimum(), 66.33, 3)
self.assertAlmostEqual(provider_extent.yMaximum(), 78.3, 3)


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

0 comments on commit 6c4a8a2

Please sign in to comment.