Skip to content

Commit 29a15ad

Browse files
committedApr 5, 2019
Move invalid size test to its own class so it can reread os.env
Signed-off-by: Marco Bernasocchi <marco@opengis.ch> add init_server method Signed-off-by: Marco Bernasocchi <marco@opengis.ch> Use own qgs application so we can change the env settings Signed-off-by: Marco Bernasocchi <marco@opengis.ch>
1 parent 64e92c1 commit 29a15ad

File tree

3 files changed

+131
-38
lines changed

3 files changed

+131
-38
lines changed
 

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ 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)
289290
ADD_PYTHON_TEST(PyQgsServerWMSGetFeatureInfo test_qgsserver_wms_getfeatureinfo.py)
290291
ADD_PYTHON_TEST(PyQgsServerWMSGetLegendGraphic test_qgsserver_wms_getlegendgraphic.py)
291292
ADD_PYTHON_TEST(PyQgsServerWMSGetPrint test_qgsserver_wms_getprint.py)

‎tests/src/python/test_qgsserver_wms_getmap.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -615,44 +615,6 @@ def test_wms_getmap_background(self):
615615
r, h = self._result(self._execute_request(qs))
616616
self._img_diff_error(r, h, "WMS_GetMap_Background_Hex")
617617

618-
def test_wms_getmap_invalid_size(self):
619-
project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
620-
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')
621-
622-
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '6000'
623-
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '6000'
624-
# test the 6000 limit from server is overridden by the more conservative 5000 in the project
625-
qs = "?" + "&".join(["%s=%s" % i for i in list({
626-
"MAP": urllib.parse.quote(project),
627-
"SERVICE": "WMS",
628-
"VERSION": "1.3.0",
629-
"REQUEST": "GetMap",
630-
"LAYERS": "",
631-
"STYLES": "",
632-
"FORMAT": "image/png",
633-
"HEIGHT": "5001",
634-
"WIDTH": "5000"
635-
}.items())])
636-
r, h = self._result(self._execute_request(qs))
637-
self.assertEqual(self.strip_version_xmlns(r), expected)
638-
639-
# test the QGIS_SERVER_WMS_MAX_XXX env vars
640-
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '3000'
641-
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '3000'
642-
qs = "?" + "&".join(["%s=%s" % i for i in list({
643-
"MAP": urllib.parse.quote(project),
644-
"SERVICE": "WMS",
645-
"VERSION": "1.3.0",
646-
"REQUEST": "GetMap",
647-
"LAYERS": "",
648-
"STYLES": "",
649-
"FORMAT": "image/png",
650-
"HEIGHT": "3000",
651-
"WIDTH": "3001"
652-
}.items())])
653-
r, h = self._result(self._execute_request(qs))
654-
self.assertEqual(self.strip_version_xmlns(r), expected)
655-
656618
def test_wms_getmap_order(self):
657619
qs = "?" + "&".join(["%s=%s" % i for i in list({
658620
"MAP": urllib.parse.quote(self.projectPath),
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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.request
31+
import urllib.parse
32+
import urllib.error
33+
34+
from utilities import (
35+
unitTestDataPath,
36+
)
37+
from qgis.testing import unittest
38+
39+
from test_qgsserver import QgsServerTestBase
40+
from qgis.core import QgsProject, QgsFontUtils, QgsApplication
41+
from qgis.server import QgsServer
42+
43+
44+
class TestQgsServerWMSGetMapSize(QgsServerTestBase):
45+
"""QGIS Server WMS Tests for GetFeatureInfo request"""
46+
47+
# Set to True to re-generate reference files for this class
48+
regenerate_reference = False
49+
50+
@classmethod
51+
def setUpClass(cls):
52+
# override the QgsServerTestBase method
53+
pass
54+
55+
@classmethod
56+
def tearDownClass(cls):
57+
# override the QgsServerTestBase method
58+
pass
59+
60+
def setUp(self):
61+
# override the QgsServerTestBase method
62+
pass
63+
64+
def tearDown(self):
65+
self.app.exitQgis()
66+
del self.app
67+
68+
def init_server(self):
69+
"""Create our own server instance so it can be called after setting up different os.environ settings"""
70+
self.app = QgsApplication([], False)
71+
self.fontFamily = QgsFontUtils.standardTestFontFamily()
72+
QgsFontUtils.loadStandardTestFonts(['All'])
73+
74+
self.testdata_path = unitTestDataPath('qgis_server') + '/'
75+
76+
d = unitTestDataPath('qgis_server') + '/'
77+
self.projectPath = os.path.join(d, "project.qgs")
78+
79+
# Clean env just to be sure
80+
env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
81+
for ev in env_vars:
82+
try:
83+
del os.environ[ev]
84+
except KeyError:
85+
pass
86+
87+
self.server = QgsServer()
88+
89+
self.project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
90+
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')
91+
92+
def test_wms_getmap_invalid_size_project(self):
93+
94+
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '6000'
95+
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '6000'
96+
self.init_server()
97+
98+
# test the 6000 limit from server is overridden by the more conservative 5000 in the project
99+
r = self._make_request(5001, 5000)
100+
self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big)
101+
102+
def test_wms_getmap_invalid_size_server(self):
103+
104+
# test the QGIS_SERVER_WMS_MAX_XXX env vars
105+
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '3000'
106+
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '3000'
107+
self.init_server()
108+
109+
# test the 3000 limit from server is overriding the less conservative 5000 in the project
110+
r = self._make_request(3001, 3000)
111+
self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big)
112+
113+
def _make_request(self, height, width):
114+
qs = "?" + "&".join(["%s=%s" % i for i in list({
115+
"MAP": urllib.parse.quote(self.project),
116+
"SERVICE": "WMS",
117+
"VERSION": "1.3.0",
118+
"REQUEST": "GetMap",
119+
"LAYERS": "",
120+
"STYLES": "",
121+
"FORMAT": "image/png",
122+
"HEIGHT": str(height),
123+
"WIDTH": str(width)
124+
}.items())])
125+
r, h = self._result(self._execute_request(qs))
126+
return self.strip_version_xmlns(r)
127+
128+
129+
if __name__ == '__main__':
130+
unittest.main()

0 commit comments

Comments
 (0)