@@ -255,156 +255,6 @@ def test_api(self):
255
255
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 ' )
256
256
self .assertEqual (self .strip_version_xmlns (body ), expected )
257
257
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
-
408
258
# WCS tests
409
259
def wcs_request_compare (self , request ):
410
260
project = self .projectPath
0 commit comments