Skip to content
Permalink
Browse files

[bugfix][server] text/plain as default info_format

Added deafult info_format (text/plain) as per specs.
Fixed error message when info format was not set or wrong.
Added test for GetFeatureInfo.
  • Loading branch information
elpaso committed Feb 22, 2016
1 parent f1e1559 commit 0a9063b42bf22f24e703db5ca19c57a86674e20f
Showing with 27 additions and 7 deletions.
  1. +1 −1 src/server/qgshttprequesthandler.cpp
  2. +1 −1 src/server/qgswmsserver.cpp
  3. +25 −5 tests/src/python/test_qgsserver.py
@@ -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;
}

@@ -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
@@ -140,25 +140,27 @@ def responseComplete(self):
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:
"""
#"""
f = open(os.path.dirname(__file__) + '/expected.txt', 'w+')
f.write(expected)
f.close()
f = open(os.path.dirname(__file__) + '/response.txt', 'w+')
f.write(response)
f.close()
"""
#"""
response = re.sub(RE_STRIP_PATH, '', response)
expected = re.sub(RE_STRIP_PATH, '', expected)
self.assertEqual(response, expected, msg="request %s failed.\n Query: %s\n Expected:\n%s\n\n Response:\n%s" % (query_string, request, expected, response))
@@ -168,8 +170,26 @@ def test_project_wms(self):
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

0 comments on commit 0a9063b

Please sign in to comment.
You can’t perform that action at this time.