Skip to content

Commit 0a9063b

Browse files
committedFeb 22, 2016
[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.
1 parent f1e1559 commit 0a9063b

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed
 

‎src/server/qgshttprequesthandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ void QgsHttpRequestHandler::setGetFeatureInfoResponse( const QDomDocument& infoD
446446
}
447447
else //unsupported format, set exception
448448
{
449-
setServiceException( QgsMapServiceException( "InvalidFormat", "Feature info format '" + mFormat + "' is not supported. Possibilities are 'text/plain', 'text/html' or 'text/xml'." ) );
449+
setServiceException( QgsMapServiceException( "InvalidFormat", "Feature info format '" + infoFormat + "' is not supported. Possibilities are 'text/plain', 'text/html' or 'text/xml'." ) );
450450
return;
451451
}
452452

‎src/server/qgswmsserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void QgsWMSServer::executeRequest()
267267
return;
268268
}
269269

270-
QString infoFormat = mParameters.value( "INFO_FORMAT" );
270+
QString infoFormat = mParameters.value( "INFO_FORMAT", "text/plain" );
271271
mRequestHandler->setGetFeatureInfoResponse( featureInfoDoc, infoFormat );
272272
}
273273
//GetContext

‎tests/src/python/test_qgsserver.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,27 @@ def responseComplete(self):
140140
self.assertEqual(response, expected)
141141

142142
# WMS tests
143-
def wms_request_compare(self, request):
143+
def wms_request_compare(self, request, extra=None, reference_file=None):
144144
project = self.testdata_path + "test+project.qgs"
145145
assert os.path.exists(project), "Project file not found: " + project
146146

147147
query_string = 'MAP=%s&SERVICE=WMS&VERSION=1.3&REQUEST=%s' % (urllib.quote(project), request)
148+
if extra is not None:
149+
query_string += extra
148150
header, body = [str(_v) for _v in self.server.handleRequest(query_string)]
149151
response = header + body
150-
f = open(self.testdata_path + request.lower() + '.txt')
152+
f = open(self.testdata_path + (request.lower() if not reference_file else reference_file) + '.txt')
151153
expected = f.read()
152154
f.close()
153155
# Store the output for debug or to regenerate the reference documents:
154-
"""
156+
#"""
155157
f = open(os.path.dirname(__file__) + '/expected.txt', 'w+')
156158
f.write(expected)
157159
f.close()
158160
f = open(os.path.dirname(__file__) + '/response.txt', 'w+')
159161
f.write(response)
160162
f.close()
161-
"""
163+
#"""
162164
response = re.sub(RE_STRIP_PATH, '', response)
163165
expected = re.sub(RE_STRIP_PATH, '', expected)
164166
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):
168170
for request in ('GetCapabilities', 'GetProjectSettings'):
169171
self.wms_request_compare(request)
170172

171-
# WMS INSPIRE tests
173+
# Test getfeatureinfo response
174+
self.wms_request_compare('GetFeatureInfo',
175+
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
176+
'info_format=text%2Fhtml&transparent=true&' +
177+
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
178+
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
179+
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
180+
'wms_getfeatureinfo-text-html')
181+
182+
# Test getfeatureinfo default info_format
183+
self.wms_request_compare('GetFeatureInfo',
184+
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
185+
'transparent=true&' +
186+
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
187+
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
188+
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
189+
'wms_getfeatureinfo-text-plain')
190+
172191
def wms_inspire_request_compare(self, request):
192+
"""WMS INSPIRE tests"""
173193
project = self.testdata_path + "test+project_inspire.qgs"
174194
assert os.path.exists(project), "Project file not found: " + project
175195

0 commit comments

Comments
 (0)
Please sign in to comment.