Skip to content

Commit

Permalink
Merge pull request #6926 from pblottiere/bugfix_ut
Browse files Browse the repository at this point in the history
[backport][server][bugfix] Cleaning GetCapabilities response
  • Loading branch information
pblottiere committed May 4, 2018
2 parents 2dc76fd + b6aaf8d commit d833970
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .docker/qgis3-build-deps.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ RUN apt-get update \
mock \
future \
termcolor \
&& apt-get autoremove -y python3-pip \
owslib \
&& apt-get clean

RUN echo "alias python=python3" >> ~/.bash_aliases
Expand Down
45 changes: 22 additions & 23 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,40 +756,39 @@ namespace QgsWms

QDomElement layerParentElem = doc.createElement( QStringLiteral( "Layer" ) );

// Root Layer title
QDomElement layerParentTitleElem = doc.createElement( QStringLiteral( "Title" ) );
QDomText layerParentTitleText = doc.createTextNode( project->title() );
layerParentTitleElem.appendChild( layerParentTitleText );
layerParentElem.appendChild( layerParentTitleElem );

// Root Layer abstract
QDomElement layerParentAbstElem = doc.createElement( QStringLiteral( "Abstract" ) );
QDomText layerParentAbstText = doc.createTextNode( project->title() );
layerParentAbstElem.appendChild( layerParentAbstText );
layerParentElem.appendChild( layerParentAbstElem );
if ( !project->title().isEmpty() )
{
// Root Layer title
QDomElement layerParentTitleElem = doc.createElement( QStringLiteral( "Title" ) );
QDomText layerParentTitleText = doc.createTextNode( project->title() );
layerParentTitleElem.appendChild( layerParentTitleText );
layerParentElem.appendChild( layerParentTitleElem );

// Root Layer abstract
QDomElement layerParentAbstElem = doc.createElement( QStringLiteral( "Abstract" ) );
QDomText layerParentAbstText = doc.createTextNode( project->title() );
layerParentAbstElem.appendChild( layerParentAbstText );
layerParentElem.appendChild( layerParentAbstElem );
}

// Root Layer name
QDomElement layerParentNameElem = doc.createElement( QStringLiteral( "Name" ) );
QString rootName = QgsServerProjectUtils::wmsRootName( *project );
if ( rootName.isEmpty() )
QString rootLayerName = QgsServerProjectUtils::wmsRootName( *project );
if ( rootLayerName.isEmpty() && !project->title().isEmpty() )
{
QDomText layerParentNameText = doc.createTextNode( project->title() );
layerParentNameElem.appendChild( layerParentNameText );
rootLayerName = project->title();
}
else

if ( !rootLayerName.isEmpty() )
{
QDomText layerParentNameText = doc.createTextNode( rootName );
QDomElement layerParentNameElem = doc.createElement( QStringLiteral( "Name" ) );
QDomText layerParentNameText = doc.createTextNode( rootLayerName );
layerParentNameElem.appendChild( layerParentNameText );
layerParentElem.appendChild( layerParentNameElem );
}
layerParentElem.appendChild( layerParentNameElem );

// Keyword list
addKeywordListElement( project, doc, layerParentElem );

// Metadata (empty but needed for OGC tests RECOMMENDATIONS)
QDomElement metaUrlElem = doc.createElement( QStringLiteral( "MetadataURL" ) );
layerParentElem.appendChild( metaUrlElem );

// Root Layer tree name
if ( projectSettings )
{
Expand Down
22 changes: 22 additions & 0 deletions tests/src/python/test_qgsserver_wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import osgeo.gdal # NOQA

from owslib.wms import WebMapService

from test_qgsserver import QgsServerTestBase
from qgis.core import QgsProject

Expand Down Expand Up @@ -395,6 +397,26 @@ def test_wms_GetProjectSettings_wms_print_layers(self):
self.assertTrue(xmlResult.find("<WMSDataSource>contextualWMSLegend=0&amp;crs=EPSG:21781&amp;dpiMode=7&amp;featureCount=10&amp;format=image/png&amp;layers=public_geo_gemeinden&amp;styles=&amp;url=https://qgiscloud.com/mhugent/qgis_unittest_wms/wms?</WMSDataSource>") != -1)
self.assertTrue(xmlResult.find("<WMSPrintLayer>contextualWMSLegend=0&amp;amp;crs=EPSG:21781&amp;amp;dpiMode=7&amp;amp;featureCount=10&amp;amp;format=image/png&amp;amp;layers=public_geo_gemeinden&amp;amp;styles=&amp;amp;url=https://qgiscloud.com/mhugent/qgis_unittest_wms_print/wms?</WMSPrintLayer>") != -1)

def test_getcapabilities_owslib(self):

# read getcapabilities document
docPath = self.testdata_path + 'getcapabilities.txt'
f = open(docPath, 'r')
doc = f.read()
f.close()

# clean header in doc
doc = doc.replace('Content-Length: 5775\n', '')
doc = doc.replace('Content-Type: text/xml; charset=utf-8\n\n', '')
doc = doc.replace('<?xml version="1.0" encoding="utf-8"?>\n', '')

# read capabilities document with owslib
w = WebMapService(None, xml=doc, version='1.3.0')

# check root layer name
rootLayerName = 'QGIS Test Project'
self.assertTrue(rootLayerName in w.contents.keys())


if __name__ == '__main__':
unittest.main()
1 change: 0 additions & 1 deletion tests/testdata/qgis_server/getcapabilities.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<MetadataURL/>
<Layer queryable="1">
<Name>testlayer èé</Name>
<Title>A test vector layer</Title>
Expand Down
1 change: 0 additions & 1 deletion tests/testdata/qgis_server/getcapabilities_inspire.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<MetadataURL/>
<Layer queryable="1">
<Name>testlayer èé</Name>
<Title>A test vector layer</Title>
Expand Down
1 change: 0 additions & 1 deletion tests/testdata/qgis_server/getprojectsettings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList>
<MetadataURL/>
<TreeName>QGIS Test Project</TreeName>
<Layer geometryType="Point" queryable="1" displayField="name" visible="1">
<Name>testlayer èé</Name>
Expand Down

0 comments on commit d833970

Please sign in to comment.