Skip to content

Commit fad4732

Browse files
committed
Separate the tests in two files since server uses static initialization
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>
1 parent 29a15ad commit fad4732

4 files changed

+130
-131
lines changed

tests/src/python/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ IF (WITH_SERVER)
286286
ADD_PYTHON_TEST(PyQgsServerPlugins test_qgsserver_plugins.py)
287287
ADD_PYTHON_TEST(PyQgsServerWMS test_qgsserver_wms.py)
288288
ADD_PYTHON_TEST(PyQgsServerWMSGetMap test_qgsserver_wms_getmap.py)
289-
ADD_PYTHON_TEST(PyQgsServerWMSGetMapSize test_qgsserver_wms_getmap_size.py)
289+
ADD_PYTHON_TEST(PyQgsServerWMSGetMapSizeProject test_qgsserver_wms_getmap_size_project.py)
290+
ADD_PYTHON_TEST(PyQgsServerWMSGetMapSizeServer test_qgsserver_wms_getmap_size_server.py)
290291
ADD_PYTHON_TEST(PyQgsServerWMSGetFeatureInfo test_qgsserver_wms_getfeatureinfo.py)
291292
ADD_PYTHON_TEST(PyQgsServerWMSGetLegendGraphic test_qgsserver_wms_getlegendgraphic.py)
292293
ADD_PYTHON_TEST(PyQgsServerWMSGetPrint test_qgsserver_wms_getprint.py)

tests/src/python/test_qgsserver_wms_getmap_size.py

-130
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsServer MaxHeight and MaxWidth Override Options.
3+
4+
From build dir, run: ctest -R PyQgsServerGetMapSize -V
5+
6+
.. note:: This test needs env vars to be set before the server is
7+
configured for the first time, for this
8+
reason it cannot run as a test case of another server
9+
test.
10+
11+
.. note:: This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation; either version 2 of the License, or
14+
(at your option) any later version.
15+
16+
"""
17+
__author__ = 'Marco Bernasocchi'
18+
__date__ = '01/04/2019'
19+
__copyright__ = 'Copyright 2019, The QGIS Project'
20+
# This will get replaced with a git SHA1 when you do a git archive
21+
__revision__ = '$Format:%H$'
22+
23+
import os
24+
25+
# Needed on Qt 5 so that the serialization of XML is consistent among all
26+
# executions
27+
os.environ['QT_HASH_SEED'] = '1'
28+
29+
30+
import urllib.parse
31+
32+
from qgis.testing import unittest
33+
34+
from test_qgsserver import QgsServerTestBase
35+
36+
37+
class TestQgsServerWMSGetMapSizeProject(QgsServerTestBase):
38+
"""QGIS Server WMS Tests for GetFeatureInfo request"""
39+
40+
# Set to True to re-generate reference files for this class
41+
regenerate_reference = False
42+
43+
def setUp(self):
44+
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '6000'
45+
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '6000'
46+
super(TestQgsServerWMSGetMapSizeProject, self).setUp()
47+
self.project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
48+
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')
49+
50+
def test_wms_getmap_invalid_size_project(self):
51+
# test the 6000 limit from server is overridden by the more conservative 5000 in the project
52+
r = make_request(self, 5001, 5000)
53+
self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big)
54+
55+
56+
def make_request(instance, height, width):
57+
qs = "?" + "&".join(["%s=%s" % i for i in list({
58+
"MAP": urllib.parse.quote(instance.project),
59+
"SERVICE": "WMS",
60+
"VERSION": "1.3.0",
61+
"REQUEST": "GetMap",
62+
"LAYERS": "",
63+
"STYLES": "",
64+
"FORMAT": "image/png",
65+
"HEIGHT": str(height),
66+
"WIDTH": str(width)
67+
}.items())])
68+
r, h = instance._result(instance._execute_request(qs))
69+
return instance.strip_version_xmlns(r)
70+
71+
72+
if __name__ == '__main__':
73+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsServer MaxHeight and MaxWidth Override Options.
3+
4+
From build dir, run: ctest -R PyQgsServerGetMapSize -V
5+
6+
.. note:: This test needs env vars to be set before the server is
7+
configured for the first time, for this
8+
reason it cannot run as a test case of another server
9+
test.
10+
11+
.. note:: This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation; either version 2 of the License, or
14+
(at your option) any later version.
15+
16+
"""
17+
__author__ = 'Marco Bernasocchi'
18+
__date__ = '01/04/2019'
19+
__copyright__ = 'Copyright 2019, The QGIS Project'
20+
# This will get replaced with a git SHA1 when you do a git archive
21+
__revision__ = '$Format:%H$'
22+
23+
import os
24+
25+
# Needed on Qt 5 so that the serialization of XML is consistent among all
26+
# executions
27+
os.environ['QT_HASH_SEED'] = '1'
28+
29+
from qgis.testing import unittest
30+
31+
from test_qgsserver import QgsServerTestBase
32+
from test_qgsserver_wms_getmap_size_project import make_request
33+
34+
35+
class TestQgsServerWMSGetMapSizeServer(QgsServerTestBase):
36+
"""QGIS Server WMS Tests for GetFeatureInfo request"""
37+
38+
# Set to True to re-generate reference files for this class
39+
regenerate_reference = False
40+
41+
def setUp(self):
42+
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '3000'
43+
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '3000'
44+
super(TestQgsServerWMSGetMapSizeServer, self).setUp()
45+
self.project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
46+
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')
47+
48+
def test_wms_getmap_invalid_size_server(self):
49+
# test the 3000 limit from server is overriding the less conservative 5000 in the project
50+
r = make_request(self, 3001, 3000)
51+
self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big)
52+
53+
54+
if __name__ == '__main__':
55+
unittest.main()

0 commit comments

Comments
 (0)