Skip to content
Permalink
Browse files

Add test and sip

add missing methods

Signed-off-by: Marco Bernasocchi <marco@opengis.ch>

Update src/server/qgsserversettings.cpp

Co-Authored-By: mbernasocchi <marco@opengis.ch>

Update src/server/qgsserversettings.cpp

Co-Authored-By: mbernasocchi <marco@opengis.ch>

Update tests/src/python/test_qgsserver_wms_getmap.py

Co-Authored-By: mbernasocchi <marco@opengis.ch>

Update src/server/qgsserversettings.h

Co-Authored-By: mbernasocchi <marco@opengis.ch>

Adress most review comments in PR

Signed-off-by: Marco Bernasocchi <marco@opengis.ch>
  • Loading branch information
mbernasocchi committed Apr 5, 2019
1 parent a938507 commit 2cda2afe3ebc5a70bf068f9075983613fdcf5f35
@@ -134,6 +134,24 @@ Show group (thousand) separator

:return: if group separator must be shown, default to ``False``.

.. versionadded:: 3.8
%End

int wmsMaxHeight() const;
%Docstring
Returns the server-wide max height of a WMS GetMap request. The lower one of this and the project configuration is used.

:return: the max height of a WMS GetMap request.

.. versionadded:: 3.8
%End

int wmsMaxWidth() const;
%Docstring
Returns the server-wide max width of a WMS GetMap request. The lower one of this and the project configuration is used.

:return: the max width of a WMS GetMap request.

.. versionadded:: 3.8
%End

@@ -165,7 +165,7 @@ void QgsServerSettings::initSettings()
// max height
const Setting sMaxHeight = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT,
QgsServerSettingsEnv::DEFAULT_VALUE,
"Maximum height for a WMS request. The most conservative between this and the project one is used",
"Maximum height for a WMS request. The lower one of this and the project configuration is used.",
"/qgis/max_wms_height",
QVariant::LongLong,
QVariant( -1 ),
@@ -363,3 +363,23 @@ QString QgsServerSettings::cacheDirectory() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
}

QString QgsServerSettings::overrideSystemLocale() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE ).toString();
}

bool QgsServerSettings::showGroupSeparator() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR ).toBool();
}

int QgsServerSettings::wmsMaxHeight() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT ).toInt();
}

int QgsServerSettings::wmsMaxWidth() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH ).toInt();
}
@@ -185,16 +185,16 @@ class SERVER_EXPORT QgsServerSettings
* \since QGIS 3.8
*/
bool showGroupSeparator() const;

/**
* Returns the max height of a WMS GetMap request.
* \returns Returns the max height of a WMS GetMap request.
* Returns the server-wide max height of a WMS GetMap request. The lower one of this and the project configuration is used.
* \returns the max height of a WMS GetMap request.
* \since QGIS 3.8
*/
int wmsMaxHeight() const;

/**
* Returns the max width of a WMS GetMap request.
* Returns the server-wide max width of a WMS GetMap request. The lower one of this and the project configuration is used.
* \returns the max width of a WMS GetMap request.
* \since QGIS 3.8
*/
@@ -1875,17 +1875,17 @@ namespace QgsWms
//and WIDTH / HEIGHT parameter is in the range allowed range
//WIDTH
int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
int wmsMaxWidthEnv = mServerSettings.wmsMaxWidth();
int wmsMaxWidthEnv = mContext.settings().wmsMaxWidth();
int wmsMaxWidth;
if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
{
// both are set, so we take the more conservative one
wmsMaxWidth = qMin( wmsMaxWidthProj, wmsMaxWidthEnv );
wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
}
else
{
// none or one are set, so we take the bigger one which is the one set or -1
wmsMaxWidth = qMax( wmsMaxWidthProj, wmsMaxWidthEnv );
wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
}

int width = this->width();
@@ -1896,17 +1896,17 @@ namespace QgsWms

//HEIGHT
int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
int wmsMaxHeightEnv = mServerSettings.wmsMaxHeight();
int wmsMaxHeightEnv = mContext.settings().wmsMaxHeight();
int wmsMaxHeight;
if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
{
// both are set, so we take the more conservative one
wmsMaxHeight = qMin( wmsMaxHeightProj, wmsMaxHeightEnv );
wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
}
else
{
// none or one are set, so we take the bigger one which is the one set or -1
wmsMaxHeight = qMax( wmsMaxHeightProj, wmsMaxHeightEnv );
wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
}

int height = this->height();
@@ -283,8 +283,6 @@ namespace QgsWms

QgsWmsParameters mWmsParameters;

QgsServerSettings mServerSettings;

QgsFeatureFilter mFeatureFilter;

const QgsProject *mProject = nullptr;
@@ -617,6 +617,11 @@ def test_wms_getmap_background(self):

def test_wms_getmap_invalid_size(self):
project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
expected = self.strip_version_xmlns(b'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="InvalidParameterValue">The requested map size is too large</ServiceException>\n</ServiceExceptionReport>\n')

os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = 6000
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = 6000
# test the 6000 limit from server is overriden by the more conservative 5000 in the project
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(project),
"SERVICE": "WMS",
@@ -628,10 +633,24 @@ def test_wms_getmap_invalid_size(self):
"HEIGHT": "5001",
"WIDTH": "5000"
}.items())])

expected = self.strip_version_xmlns(b'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="InvalidParameterValue">The requested map size is too large</ServiceException>\n</ServiceExceptionReport>\n')
r, h = self._result(self._execute_request(qs))
self.assertEqual(self.strip_version_xmlns(r), expected)

# test the QGIS_SERVER_WMS_MAX_XXX env vars
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = 3000
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = 3000
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(project),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"LAYERS": "",
"STYLES": "",
"FORMAT": "image/png",
"HEIGHT": "3000",
"WIDTH": "3001"
}.items())])
r, h = self._result(self._execute_request(qs))
self.assertEqual(self.strip_version_xmlns(r), expected)

def test_wms_getmap_order(self):

0 comments on commit 2cda2af

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