Skip to content

Commit

Permalink
[bugfix][server] text/plain as default info_format
Browse files Browse the repository at this point in the history
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 0a9063b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/server/qgshttprequesthandler.cpp
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/qgswmsserver.cpp
Expand Up @@ -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
Expand Down
30 changes: 25 additions & 5 deletions tests/src/python/test_qgsserver.py
Expand Up @@ -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))
Expand All @@ -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

Expand Down

0 comments on commit 0a9063b

Please sign in to comment.