Skip to content

Commit

Permalink
Add test and sip
Browse files Browse the repository at this point in the history
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 2cda2af
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
18 changes: 18 additions & 0 deletions python/server/auto_generated/qgsserversettings.sip.in
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion src/server/qgsserversettings.cpp
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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();
}
8 changes: 4 additions & 4 deletions src/server/qgsserversettings.h
Expand Up @@ -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
*/
Expand Down
12 changes: 6 additions & 6 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/server/services/wms/qgswmsrenderer.h
Expand Up @@ -283,8 +283,6 @@ namespace QgsWms

QgsWmsParameters mWmsParameters;

QgsServerSettings mServerSettings;

QgsFeatureFilter mFeatureFilter;

const QgsProject *mProject = nullptr;
Expand Down
23 changes: 21 additions & 2 deletions tests/src/python/test_qgsserver_wms_getmap.py
Expand Up @@ -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",
Expand All @@ -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):
Expand Down

0 comments on commit 2cda2af

Please sign in to comment.