Skip to content
Permalink
Browse files

Merge pull request #6926 from pblottiere/bugfix_ut

[backport][server][bugfix] Cleaning GetCapabilities response
  • Loading branch information
pblottiere committed May 4, 2018
2 parents 2dc76fd + b6aaf8d commit d8339701b7f3a3cfb72f297ee111bb0d1e652ad0
@@ -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
@@ -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 )
{
@@ -31,6 +31,8 @@

import osgeo.gdal # NOQA

from owslib.wms import WebMapService

from test_qgsserver import QgsServerTestBase
from qgis.core import QgsProject

@@ -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()
@@ -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>
@@ -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>
@@ -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>

0 comments on commit d833970

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