Skip to content

Commit b8ebbc1

Browse files
committed
[Server][Tests] Add PyQgsServerWFS test
1 parent d7a48c6 commit b8ebbc1

File tree

10 files changed

+461
-256
lines changed

10 files changed

+461
-256
lines changed

src/server/services/wfs/qgswfsparameters.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ namespace QgsWfs
136136
else if ( fStr.compare( QLatin1String( "geojson" ), Qt::CaseInsensitive ) == 0 )
137137
f = Format::GeoJSON;
138138

139+
if ( f == Format::NONE &&
140+
request().compare( QLatin1String( "describefeaturetype" ), Qt::CaseInsensitive ) == 0 &&
141+
fStr.compare( QLatin1String( "xmlschema" ), Qt::CaseInsensitive ) == 0 )
142+
f = Format::GML2;
143+
139144
return f;
140145
}
141146

@@ -144,6 +149,14 @@ namespace QgsWfs
144149
return value( ParameterName::SRSNAME ).toString();
145150
}
146151

152+
QString QgsWfsParameters::request() const
153+
{
154+
if ( mRequestParameters.contains( "REQUEST" ) )
155+
return mRequestParameters["REQUEST"];
156+
else
157+
return QString();
158+
}
159+
147160
QString QgsWfsParameters::version() const
148161
{
149162
// VERSION parameter is not managed with other parameters because

src/server/services/wfs/qgswfsparameters.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ namespace QgsWfs
8585
*/
8686
void dump() const;
8787

88-
<<<<<<< HEAD
89-
/** Returns VERSION parameter as a string or an empty string if not
90-
=======
9188
/**
9289
* Returns REQUEST parameter as a string or an empty string if not
9390
* defined.
@@ -97,7 +94,6 @@ namespace QgsWfs
9794

9895
/**
9996
* Returns VERSION parameter as a string or an empty string if not
100-
>>>>>>> 747f00d... QgsWfsParameters
10197
* defined.
10298
* \returns version
10399
*/

tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ IF (WITH_SERVER)
223223
ADD_PYTHON_TEST(PyQgsServerProjectUtils test_qgsserver_projectutils.py)
224224
ADD_PYTHON_TEST(PyQgsServerSecurity test_qgsserver_security.py)
225225
ADD_PYTHON_TEST(PyQgsServerAccessControl test_qgsserver_accesscontrol.py)
226+
ADD_PYTHON_TEST(PyQgsServerWFS test_qgsserver_wfs.py)
226227
ADD_PYTHON_TEST(PyQgsServerWFST test_qgsserver_wfst.py)
227228
ADD_PYTHON_TEST(PyQgsOfflineEditingWFS test_offline_editing_wfs.py)
228229
ADD_PYTHON_TEST(PyQgsAuthManagerPasswordOWSTest test_authmanager_password_ows.py)

tests/src/python/test_qgsserver.py

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -255,156 +255,6 @@ def test_api(self):
255255
expected = self.strip_version_xmlns(b'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="Service configuration error">Service unknown or unsupported</ServiceException>\n</ServiceExceptionReport>\n')
256256
self.assertEqual(self.strip_version_xmlns(body), expected)
257257

258-
# WFS tests
259-
def wfs_request_compare(self, request):
260-
project = self.testdata_path + "test_project_wfs.qgs"
261-
assert os.path.exists(project), "Project file not found: " + project
262-
263-
query_string = '?MAP=%s&SERVICE=WFS&VERSION=1.0.0&REQUEST=%s' % (urllib.parse.quote(project), request)
264-
header, body = self._execute_request(query_string)
265-
self.assert_headers(header, body)
266-
response = header + body
267-
reference_path = self.testdata_path + 'wfs_' + request.lower() + '.txt'
268-
self.store_reference(reference_path, response)
269-
f = open(reference_path, 'rb')
270-
expected = f.read()
271-
f.close()
272-
response = re.sub(RE_STRIP_UNCHECKABLE, b'', response)
273-
expected = re.sub(RE_STRIP_UNCHECKABLE, b'', expected)
274-
275-
self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s" % (query_string, request))
276-
277-
def test_project_wfs(self):
278-
"""Test some WFS request"""
279-
for request in ('GetCapabilities', 'DescribeFeatureType'):
280-
self.wfs_request_compare(request)
281-
282-
def wfs_getfeature_compare(self, requestid, request):
283-
project = self.testdata_path + "test_project_wfs.qgs"
284-
assert os.path.exists(project), "Project file not found: " + project
285-
286-
query_string = '?MAP=%s&SERVICE=WFS&VERSION=1.0.0&REQUEST=%s' % (urllib.parse.quote(project), request)
287-
header, body = self._execute_request(query_string)
288-
self.result_compare(
289-
'wfs_getfeature_' + requestid + '.txt',
290-
"request %s failed.\n Query: %s" % (
291-
query_string,
292-
request,
293-
),
294-
header, body
295-
)
296-
297-
def test_getfeature(self):
298-
tests = []
299-
tests.append(('nobbox', 'GetFeature&TYPENAME=testlayer'))
300-
tests.append(('startindex2', 'GetFeature&TYPENAME=testlayer&STARTINDEX=2'))
301-
tests.append(('limit2', 'GetFeature&TYPENAME=testlayer&MAXFEATURES=2'))
302-
tests.append(('start1_limit1', 'GetFeature&TYPENAME=testlayer&MAXFEATURES=1&STARTINDEX=1'))
303-
304-
for id, req in tests:
305-
self.wfs_getfeature_compare(id, req)
306-
307-
def test_wfs_getcapabilities_url(self):
308-
"""Check that URL in GetCapabilities response is complete"""
309-
# empty url in project
310-
project = os.path.join(self.testdata_path, "test_project_without_urls.qgs")
311-
qs = "?" + "&".join(["%s=%s" % i for i in list({
312-
"MAP": urllib.parse.quote(project),
313-
"SERVICE": "WFS",
314-
"VERSION": "1.3.0",
315-
"REQUEST": "GetCapabilities",
316-
"STYLES": ""
317-
}.items())])
318-
319-
r, h = self._result(self._execute_request(qs))
320-
321-
for item in str(r).split("\\n"):
322-
if "onlineResource" in item:
323-
self.assertEqual("onlineResource=\"?" in item, True)
324-
325-
# url well defined in query string
326-
project = os.path.join(self.testdata_path, "test_project_without_urls.qgs")
327-
qs = "https://www.qgis-server.org?" + "&".join(["%s=%s" % i for i in list({
328-
"MAP": urllib.parse.quote(project),
329-
"SERVICE": "WFS",
330-
"VERSION": "1.3.0",
331-
"REQUEST": "GetCapabilities",
332-
"STYLES": ""
333-
}.items())])
334-
335-
r, h = self._result(self._execute_request(qs))
336-
337-
for item in str(r).split("\\n"):
338-
if "onlineResource" in item:
339-
self.assertTrue("onlineResource=\"https://www.qgis-server.org?" in item, True)
340-
341-
# url well defined in project
342-
project = os.path.join(self.testdata_path, "test_project_with_urls.qgs")
343-
qs = "?" + "&".join(["%s=%s" % i for i in list({
344-
"MAP": urllib.parse.quote(project),
345-
"SERVICE": "WFS",
346-
"VERSION": "1.3.0",
347-
"REQUEST": "GetCapabilities",
348-
"STYLES": ""
349-
}.items())])
350-
351-
r, h = self._result(self._execute_request(qs))
352-
353-
for item in str(r).split("\\n"):
354-
if "onlineResource" in item:
355-
self.assertEqual("onlineResource=\"my_wfs_advertised_url\"" in item, True)
356-
357-
def result_compare(self, file_name, error_msg_header, header, body):
358-
self.assert_headers(header, body)
359-
response = header + body
360-
reference_path = self.testdata_path + file_name
361-
self.store_reference(reference_path, response)
362-
f = open(reference_path, 'rb')
363-
expected = f.read()
364-
f.close()
365-
response = re.sub(RE_STRIP_UNCHECKABLE, b'', response)
366-
expected = re.sub(RE_STRIP_UNCHECKABLE, b'', expected)
367-
self.assertXMLEqual(response, expected, msg="%s\n" % (error_msg_header))
368-
369-
def wfs_getfeature_post_compare(self, requestid, request):
370-
project = self.testdata_path + "test_project_wfs.qgs"
371-
assert os.path.exists(project), "Project file not found: " + project
372-
373-
query_string = '?MAP={}'.format(urllib.parse.quote(project))
374-
header, body = self._execute_request(query_string, requestMethod=QgsServerRequest.PostMethod, data=request.encode('utf-8'))
375-
376-
self.result_compare(
377-
'wfs_getfeature_{}.txt'.format(requestid),
378-
"GetFeature in POST for '{}' failed.".format(requestid),
379-
header, body,
380-
)
381-
382-
def test_getfeature_post(self):
383-
template = """<?xml version="1.0" encoding="UTF-8"?>
384-
<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">
385-
<wfs:Query typeName="testlayer" xmlns:feature="http://www.qgis.org/gml">
386-
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
387-
<ogc:BBOX>
388-
<ogc:PropertyName>geometry</ogc:PropertyName>
389-
<gml:Envelope xmlns:gml="http://www.opengis.net/gml">
390-
<gml:lowerCorner>8 44</gml:lowerCorner>
391-
<gml:upperCorner>9 45</gml:upperCorner>
392-
</gml:Envelope>
393-
</ogc:BBOX>
394-
</ogc:Filter>
395-
</wfs:Query>
396-
</wfs:GetFeature>
397-
"""
398-
399-
tests = []
400-
tests.append(('nobbox_post', template.format("")))
401-
tests.append(('startindex2_post', template.format('startIndex="2"')))
402-
tests.append(('limit2_post', template.format('maxFeatures="2"')))
403-
tests.append(('start1_limit1_post', template.format('startIndex="1" maxFeatures="1"')))
404-
405-
for id, req in tests:
406-
self.wfs_getfeature_post_compare(id, req)
407-
408258
# WCS tests
409259
def wcs_request_compare(self, request):
410260
project = self.projectPath

0 commit comments

Comments
 (0)