Skip to content

Commit

Permalink
Add unit test for WFS GetFeature Within for EPSG 3857 and 'fake' EPSG…
Browse files Browse the repository at this point in the history
… 3857.
  • Loading branch information
ismailsunni authored and nyalldawson committed Jun 2, 2020
1 parent d92564a commit fabdb64
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 5 deletions.
75 changes: 70 additions & 5 deletions tests/src/python/test_qgsserver_wfs.py
Expand Up @@ -189,7 +189,7 @@ def test_wfs_getcapabilities_100_url(self):
self.assertEqual(
"onlineResource=\"my_wfs_advertised_url\"" in item, True)

def result_compare(self, file_name, error_msg_header, header, body):
def result_compare(self, file_name, error_msg_header, header, body, expectEqual=True):
self.assert_headers(header, body)
response = header + body
reference_path = self.testdata_path + file_name
Expand All @@ -202,7 +202,11 @@ def result_compare(self, file_name, error_msg_header, header, body):
self.assertXMLEqual(response, expected, msg="%s\n" %
(error_msg_header))

def wfs_getfeature_post_compare(self, requestid, request):
# If do not expect equal and pass the line above, should throw and assertion error.
if not expectEqual:
self.assertFalse(True, msg='It should get different result for %s.' % error_msg_header)

def wfs_getfeature_post_compare(self, requestid, request, expectEqual=True):
project = self.testdata_path + "test_project_wfs.qgs"
assert os.path.exists(project), "Project file not found: " + project

Expand All @@ -213,11 +217,14 @@ def wfs_getfeature_post_compare(self, requestid, request):
self.result_compare(
'wfs_getfeature_{}.txt'.format(requestid),
"GetFeature in POST for '{}' failed.".format(requestid),
header, body,
header,
body,
expectEqual
)

def test_getfeature_post(self):
tests = []
expectNotEqualTests = []

template = """<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature service="WFS" version="1.0.0" {} xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
Expand Down Expand Up @@ -259,7 +266,7 @@ def test_getfeature_post(self):

# Issue https://github.com/qgis/QGIS/issues/36398
# Check get feature within linear ring with srsName=EPSG:4326
withinFilterTemplate = """<?xml version="1.0" encoding="UTF-8"?>
within4326FilterTemplate = """<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature service="WFS" version="1.0.0" {} xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<wfs:Query typeName="testlayer" srsName="EPSG:4326" xmlns:feature="http://www.qgis.org/gml">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
Expand All @@ -283,7 +290,62 @@ def test_getfeature_post(self):
</wfs:Query>
</wfs:GetFeature>
"""
tests.append(('withinFilterTemplate_post', withinFilterTemplate.format("")))
tests.append(('within4326FilterTemplate_post', within4326FilterTemplate.format("")))

# Keep the coordinate in 4326, but change the srsName to 3857 (should returns different result)
# The reference file (withinFake3857FilterTemplate_post.txt) is copied from within4326FilterTemplate_post.txt
withinFake3857FilterTemplate = """<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature service="WFS" version="1.0.0" {} xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<wfs:Query typeName="testlayer" srsName="EPSG:4326" xmlns:feature="http://www.qgis.org/gml">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<Within>
<PropertyName>geometry</PropertyName>
<Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<exterior>
<LinearRing srsName="EPSG:3857">
<posList srsDimension="2">
8 44
9 44
9 45
8 45
8 44
</posList>
</LinearRing>
</exterior>
</Polygon>
</Within>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
"""
expectNotEqualTests.append(('withinFake3857FilterTemplate_post', withinFake3857FilterTemplate.format("")))

# Now test with EPSG 3857 and proper 3857 coordinates
within3857FilterTemplate = """<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature service="WFS" version="1.0.0" {} xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<wfs:Query typeName="testlayer" srsName="EPSG:4326" xmlns:feature="http://www.qgis.org/gml">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<Within>
<PropertyName>geometry</PropertyName>
<Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<exterior>
<LinearRing srsName="EPSG:3857">
<posList srsDimension="2">
890555.93 5465442.18
1001875.42, 5465442.18
1001875.42, 5621521.49
890555.93, 5621521.49
890555.93 5465442.18
</posList>
</LinearRing>
</exterior>
</Polygon>
</Within>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
"""
tests.append(('within3857FilterTemplate_post', within3857FilterTemplate.format("")))

srsTwoLayersTemplate = """<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature service="WFS" version="1.0.0" {} xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
Expand Down Expand Up @@ -418,6 +480,9 @@ def test_getfeature_post(self):
"""
tests.append(('nobbox_post', template.format("")))

for id, req in expectNotEqualTests:
self.wfs_getfeature_post_compare(id, req, expectEqual=False)

for id, req in tests:
self.wfs_getfeature_post_compare(id, req)

Expand Down
@@ -0,0 +1,60 @@
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8

<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8,44 9,45</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<qgs:testlayer fid="testlayer.0">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20349634,44.90148253 8.20349634,44.90148253</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
</Point>
</qgs:geometry>
<qgs:id>1</qgs:id>
<qgs:name>one</qgs:name>
<qgs:utf8nameè>one èé</qgs:utf8nameè>
</qgs:testlayer>
</gml:featureMember>
<gml:featureMember>
<qgs:testlayer fid="testlayer.1">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20354699,44.90143568 8.20354699,44.90143568</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20354699,44.90143568</coordinates>
</Point>
</qgs:geometry>
<qgs:id>2</qgs:id>
<qgs:name>two</qgs:name>
<qgs:utf8nameè>two àò</qgs:utf8nameè>
</qgs:testlayer>
</gml:featureMember>
<gml:featureMember>
<qgs:testlayer fid="testlayer.2">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20345931,44.90139484</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20345931,44.90139484</coordinates>
</Point>
</qgs:geometry>
<qgs:id>3</qgs:id>
<qgs:name>three</qgs:name>
<qgs:utf8nameè>three èé↓</qgs:utf8nameè>
</qgs:testlayer>
</gml:featureMember>
</wfs:FeatureCollection>
@@ -0,0 +1,60 @@
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8

<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20354699,44.90148253</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<qgs:testlayer fid="testlayer.0">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20349634,44.90148253 8.20349634,44.90148253</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
</Point>
</qgs:geometry>
<qgs:id>1</qgs:id>
<qgs:name>one</qgs:name>
<qgs:utf8nameè>one èé</qgs:utf8nameè>
</qgs:testlayer>
</gml:featureMember>
<gml:featureMember>
<qgs:testlayer fid="testlayer.1">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20354699,44.90143568 8.20354699,44.90143568</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20354699,44.90143568</coordinates>
</Point>
</qgs:geometry>
<qgs:id>2</qgs:id>
<qgs:name>two</qgs:name>
<qgs:utf8nameè>two àò</qgs:utf8nameè>
</qgs:testlayer>
</gml:featureMember>
<gml:featureMember>
<qgs:testlayer fid="testlayer.2">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20345931,44.90139484</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20345931,44.90139484</coordinates>
</Point>
</qgs:geometry>
<qgs:id>3</qgs:id>
<qgs:name>three</qgs:name>
<qgs:utf8nameè>three èé↓</qgs:utf8nameè>
</qgs:testlayer>
</gml:featureMember>
</wfs:FeatureCollection>

0 comments on commit fabdb64

Please sign in to comment.