@@ -4650,6 +4650,58 @@ def testWFS20CaseInsensitiveKVP(self):
4650
4650
assert QgsGeometry .compare (vl_extent .asPolygon ()[0 ], reference .asPolygon ()[0 ],
4651
4651
0.00001 ), 'Expected {}, got {}' .format (reference .asWkt (), vl_extent .asWkt ())
4652
4652
4653
+ def testGetCapabilitiesReturnWFSException (self ):
4654
+ """Test parsing of WFS exception
4655
+ """
4656
+ endpoint = self .__class__ .basetestpath + '/fake_qgis_http_endpoint_testGetCapabilitiesReturnWFSException'
4657
+
4658
+ get_cap_response = """<?xml version="1.0" encoding="UTF-8"?>
4659
+ <ExceptionReport xmlns="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4660
+ xsi:schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" version="1.0.0" language="en">
4661
+ <Exception exceptionCode="foo" locator="service">
4662
+ <ExceptionText>bar</ExceptionText>
4663
+ </Exception>
4664
+ </ExceptionReport>
4665
+ """ .encode ('UTF-8' )
4666
+
4667
+ with open (sanitize (endpoint ,
4668
+ '?SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0' ),
4669
+ 'wb' ) as f :
4670
+ f .write (get_cap_response )
4671
+
4672
+ with MessageLogger ('WFS' ) as logger :
4673
+ vl = QgsVectorLayer ("url='http://" + endpoint + "' typename='my:typename' version='1.0.0'" , 'test' , 'WFS' )
4674
+ self .assertFalse (vl .isValid ())
4675
+
4676
+ self .assertEqual (len (logger .messages ()), 1 , logger .messages ())
4677
+ self .assertTrue ("foo: bar" in logger .messages ()[0 ].decode ('UTF-8' ), logger .messages ())
4678
+
4679
+ def testGetCapabilitiesReturnWMSException (self ):
4680
+ """Test fix for https://github.com/qgis/QGIS/issues/29866
4681
+ """
4682
+ endpoint = self .__class__ .basetestpath + '/fake_qgis_http_endpoint_testGetCapabilitiesReturnWMSxception'
4683
+
4684
+ get_cap_response = """<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
4685
+ <!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd">
4686
+ <ServiceExceptionReport version="1.1.1">
4687
+ <ServiceException code="InvalidFormat">
4688
+ Can't recognize service requested.
4689
+ </ServiceException>
4690
+ </ServiceExceptionReport>
4691
+ """ .encode ('UTF-8' )
4692
+
4693
+ with open (sanitize (endpoint ,
4694
+ '?SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0' ),
4695
+ 'wb' ) as f :
4696
+ f .write (get_cap_response )
4697
+
4698
+ with MessageLogger ('WFS' ) as logger :
4699
+ vl = QgsVectorLayer ("url='http://" + endpoint + "' typename='my:typename' version='1.0.0'" , 'test' , 'WFS' )
4700
+ self .assertFalse (vl .isValid ())
4701
+
4702
+ self .assertEqual (len (logger .messages ()), 1 , logger .messages ())
4703
+ self .assertTrue ("InvalidFormat: Can't recognize service requested." in logger .messages ()[0 ].decode ('UTF-8' ), logger .messages ())
4704
+
4653
4705
4654
4706
if __name__ == '__main__' :
4655
4707
unittest .main ()
0 commit comments