Merge pull request #2830 from elpaso/server-fix-info_format2

[bugfix][server] text/plain as default info_format
This commit is contained in:
Alessandro Pasotti 2016-02-22 22:28:25 +01:00
commit bf583c7236
5 changed files with 58 additions and 5 deletions

View File

@ -446,7 +446,7 @@ void QgsHttpRequestHandler::setGetFeatureInfoResponse( const QDomDocument& infoD
}
else //unsupported format, set exception
{
setServiceException( QgsMapServiceException( "InvalidFormat", "Feature info format '" + mFormat + "' is not supported. Possibilities are 'text/plain', 'text/html' or 'text/xml'." ) );
setServiceException( QgsMapServiceException( "InvalidFormat", "Feature info format '" + infoFormat + "' is not supported. Possibilities are 'text/plain', 'text/html' or 'text/xml'." ) );
return;
}

View File

@ -267,7 +267,7 @@ void QgsWMSServer::executeRequest()
return;
}
QString infoFormat = mParameters.value( "INFO_FORMAT" );
QString infoFormat = mParameters.value( "INFO_FORMAT", "text/plain" );
mRequestHandler->setGetFeatureInfoResponse( featureInfoDoc, infoFormat );
}
//GetContext

View File

@ -140,14 +140,16 @@ class TestQgsServer(unittest.TestCase):
self.assertEqual(response, expected)
# WMS tests
def wms_request_compare(self, request):
def wms_request_compare(self, request, extra=None, reference_file=None):
project = self.testdata_path + "test+project.qgs"
assert os.path.exists(project), "Project file not found: " + project
query_string = 'MAP=%s&SERVICE=WMS&VERSION=1.3&REQUEST=%s' % (urllib.quote(project), request)
if extra is not None:
query_string += extra
header, body = [str(_v) for _v in self.server.handleRequest(query_string)]
response = header + body
f = open(self.testdata_path + request.lower() + '.txt')
f = open(self.testdata_path + (request.lower() if not reference_file else reference_file) + '.txt')
expected = f.read()
f.close()
# Store the output for debug or to regenerate the reference documents:
@ -168,8 +170,26 @@ class TestQgsServer(unittest.TestCase):
for request in ('GetCapabilities', 'GetProjectSettings'):
self.wms_request_compare(request)
# WMS INSPIRE tests
# Test getfeatureinfo response
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
'info_format=text%2Fhtml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
'wms_getfeatureinfo-text-html')
# Test getfeatureinfo default info_format
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
'transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
'wms_getfeatureinfo-text-plain')
def wms_inspire_request_compare(self, request):
"""WMS INSPIRE tests"""
project = self.testdata_path + "test+project_inspire.qgs"
assert os.path.exists(project), "Project file not found: " + project

View File

@ -0,0 +1,21 @@
Content-Length: 360
Content-Type: text/html; charset=utf-8
<HEAD>
<TITLE> GetFeatureInfo results </TITLE>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</HEAD>
<BODY>
<TABLE border=1 width=100%>
<TR><TH width=25%>Layer</TH><TD>testlayer èé</TD></TR>
</BR><TABLE border=1 width=100%>
<TR><TH>Feature</TH><TD>2</TD></TR>
<TR><TH>id</TH><TD>3</TD></TR>
<TR><TH>name</TH><TD>three</TD></TR>
<TR><TH>utf8nameè</TH><TD>three èé↓</TD></TR>
<TR><TH>geometry</TH><TD>Point (913204.9128 5606011.4565)</TD></TR>
</TABLE>
</BR>
</TABLE>
<BR></BR>
</BODY>

View File

@ -0,0 +1,12 @@
Content-Length: 157
Content-Type: text/plain; charset=utf-8
GetFeatureInfo results
Layer 'testlayer èé'
Feature 2
id = '3'
name = 'three'
utf8nameè = 'three èé↓'
geometry = 'Point (913204.9128 5606011.4565)'