Skip to content

Commit

Permalink
Separate the tests in two files since server uses static initialization
Browse files Browse the repository at this point in the history
and thus we cannot change it's settings once it is created

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

Signed-off-by: Marco Bernasocchi <marco@opengis.ch>
  • Loading branch information
mbernasocchi committed Apr 5, 2019
1 parent 29a15ad commit fad4732
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 131 deletions.
3 changes: 2 additions & 1 deletion tests/src/python/CMakeLists.txt
Expand Up @@ -286,7 +286,8 @@ IF (WITH_SERVER)
ADD_PYTHON_TEST(PyQgsServerPlugins test_qgsserver_plugins.py)
ADD_PYTHON_TEST(PyQgsServerWMS test_qgsserver_wms.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetMap test_qgsserver_wms_getmap.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetMapSize test_qgsserver_wms_getmap_size.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetMapSizeProject test_qgsserver_wms_getmap_size_project.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetMapSizeServer test_qgsserver_wms_getmap_size_server.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetFeatureInfo test_qgsserver_wms_getfeatureinfo.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetLegendGraphic test_qgsserver_wms_getlegendgraphic.py)
ADD_PYTHON_TEST(PyQgsServerWMSGetPrint test_qgsserver_wms_getprint.py)
Expand Down
130 changes: 0 additions & 130 deletions tests/src/python/test_qgsserver_wms_getmap_size.py

This file was deleted.

73 changes: 73 additions & 0 deletions tests/src/python/test_qgsserver_wms_getmap_size_project.py
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsServer MaxHeight and MaxWidth Override Options.
From build dir, run: ctest -R PyQgsServerGetMapSize -V
.. note:: This test needs env vars to be set before the server is
configured for the first time, for this
reason it cannot run as a test case of another server
test.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Marco Bernasocchi'
__date__ = '01/04/2019'
__copyright__ = 'Copyright 2019, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os

# Needed on Qt 5 so that the serialization of XML is consistent among all
# executions
os.environ['QT_HASH_SEED'] = '1'


import urllib.parse

from qgis.testing import unittest

from test_qgsserver import QgsServerTestBase


class TestQgsServerWMSGetMapSizeProject(QgsServerTestBase):
"""QGIS Server WMS Tests for GetFeatureInfo request"""

# Set to True to re-generate reference files for this class
regenerate_reference = False

def setUp(self):
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '6000'
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '6000'
super(TestQgsServerWMSGetMapSizeProject, self).setUp()
self.project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
self.expected_too_big = 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')

def test_wms_getmap_invalid_size_project(self):
# test the 6000 limit from server is overridden by the more conservative 5000 in the project
r = make_request(self, 5001, 5000)
self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big)


def make_request(instance, height, width):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(instance.project),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"LAYERS": "",
"STYLES": "",
"FORMAT": "image/png",
"HEIGHT": str(height),
"WIDTH": str(width)
}.items())])
r, h = instance._result(instance._execute_request(qs))
return instance.strip_version_xmlns(r)


if __name__ == '__main__':
unittest.main()
55 changes: 55 additions & 0 deletions tests/src/python/test_qgsserver_wms_getmap_size_server.py
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsServer MaxHeight and MaxWidth Override Options.
From build dir, run: ctest -R PyQgsServerGetMapSize -V
.. note:: This test needs env vars to be set before the server is
configured for the first time, for this
reason it cannot run as a test case of another server
test.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Marco Bernasocchi'
__date__ = '01/04/2019'
__copyright__ = 'Copyright 2019, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os

# Needed on Qt 5 so that the serialization of XML is consistent among all
# executions
os.environ['QT_HASH_SEED'] = '1'

from qgis.testing import unittest

from test_qgsserver import QgsServerTestBase
from test_qgsserver_wms_getmap_size_project import make_request


class TestQgsServerWMSGetMapSizeServer(QgsServerTestBase):
"""QGIS Server WMS Tests for GetFeatureInfo request"""

# Set to True to re-generate reference files for this class
regenerate_reference = False

def setUp(self):
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '3000'
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '3000'
super(TestQgsServerWMSGetMapSizeServer, self).setUp()
self.project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
self.expected_too_big = 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')

def test_wms_getmap_invalid_size_server(self):
# test the 3000 limit from server is overriding the less conservative 5000 in the project
r = make_request(self, 3001, 3000)
self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big)


if __name__ == '__main__':
unittest.main()

0 comments on commit fad4732

Please sign in to comment.