Skip to content

Commit d24de06

Browse files
committedNov 22, 2017
Split some WMS tests
1 parent b058df7 commit d24de06

File tree

5 files changed

+1744
-1597
lines changed

5 files changed

+1744
-1597
lines changed
 

‎tests/src/python/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ IF (WITH_SERVER)
233233
ADD_PYTHON_TEST(PyQgsServer test_qgsserver.py)
234234
ADD_PYTHON_TEST(PyQgsServerPlugins test_qgsserver_plugins.py)
235235
ADD_PYTHON_TEST(PyQgsServerWMS test_qgsserver_wms.py)
236+
ADD_PYTHON_TEST(PyQgsServerWMSGetMap test_qgsserver_wms_getmap.py)
237+
ADD_PYTHON_TEST(PyQgsServerWMSGetLegendGraphic test_qgsserver_wms_getlegendgraphic.py)
238+
ADD_PYTHON_TEST(PyQgsServerWMSGetPrint test_qgsserver_wms_getprint.py)
236239
ADD_PYTHON_TEST(PyQgsServerSettings test_qgsserver_settings.py)
237240
ADD_PYTHON_TEST(PyQgsServerProjectUtils test_qgsserver_projectutils.py)
238241
ADD_PYTHON_TEST(PyQgsServerSecurity test_qgsserver_security.py)

‎tests/src/python/test_qgsserver_wms.py

Lines changed: 0 additions & 1597 deletions
Large diffs are not rendered by default.
Lines changed: 474 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,474 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsServer WMS.
3+
4+
From build dir, run: ctest -R PyQgsServerWMS -V
5+
6+
7+
.. note:: This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
12+
"""
13+
__author__ = 'Alessandro Pasotti'
14+
__date__ = '25/05/2015'
15+
__copyright__ = 'Copyright 2015, The QGIS Project'
16+
# This will get replaced with a git SHA1 when you do a git archive
17+
__revision__ = '$Format:%H$'
18+
19+
import os
20+
21+
# Needed on Qt 5 so that the serialization of XML is consistent among all executions
22+
os.environ['QT_HASH_SEED'] = '1'
23+
24+
import re
25+
import urllib.request
26+
import urllib.parse
27+
import urllib.error
28+
29+
from qgis.testing import unittest
30+
from qgis.PyQt.QtCore import QSize
31+
32+
import osgeo.gdal # NOQA
33+
34+
from test_qgsserver import QgsServerTestBase
35+
from qgis.core import QgsProject
36+
37+
# Strip path and content length because path may vary
38+
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
39+
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
40+
41+
42+
class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
43+
44+
"""QGIS Server WMS Tests for GetLegendGraphic request"""
45+
46+
def test_getLegendGraphics(self):
47+
"""Test that does not return an exception but an image"""
48+
parms = {
49+
'MAP': self.testdata_path + "test_project.qgs",
50+
'SERVICE': 'WMS',
51+
'VERSION': '1.3.0',
52+
'REQUEST': 'GetLegendGraphic',
53+
'FORMAT': 'image/png',
54+
# 'WIDTH': '20', # optional
55+
# 'HEIGHT': '20', # optional
56+
'LAYER': 'testlayer%20èé',
57+
}
58+
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
59+
h, r = self._execute_request(qs)
60+
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
61+
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))
62+
63+
def test_getLegendGraphics_invalid_parameters(self):
64+
"""Test that does return an exception"""
65+
qs = "?" + "&".join(["%s=%s" % i for i in list({
66+
"MAP": urllib.parse.quote(self.projectPath),
67+
"SERVICE": "WMS",
68+
"VERSION": "1.1.1",
69+
"REQUEST": "GetLegendGraphic",
70+
"LAYER": "Country,Hello,db_point",
71+
"LAYERTITLE": "FALSE",
72+
"FORMAT": "image/png",
73+
"HEIGHT": "500",
74+
"WIDTH": "500",
75+
"RULE": "1",
76+
"BBOX": "-151.7,-38.9,51.0,78.0",
77+
"CRS": "EPSG:4326"
78+
}.items())])
79+
80+
r, h = self._result(self._execute_request(qs))
81+
err = b"BBOX parameter cannot be combined with RULE" in r
82+
self.assertTrue(err)
83+
84+
def test_wms_GetLegendGraphic_LayerSpace(self):
85+
qs = "?" + "&".join(["%s=%s" % i for i in list({
86+
"MAP": urllib.parse.quote(self.projectPath),
87+
"SERVICE": "WMS",
88+
"VERSION": "1.1.1",
89+
"REQUEST": "GetLegendGraphic",
90+
"LAYER": "Country,Hello",
91+
"FORMAT": "image/png",
92+
# "HEIGHT": "500",
93+
# "WIDTH": "500",
94+
"LAYERSPACE": "50.0",
95+
"LAYERFONTBOLD": "TRUE",
96+
"LAYERFONTSIZE": "30",
97+
"ITEMFONTBOLD": "TRUE",
98+
"ITEMFONTSIZE": "20",
99+
"LAYERFONTFAMILY": self.fontFamily,
100+
"ITEMFONTFAMILY": self.fontFamily,
101+
"LAYERTITLE": "TRUE",
102+
"CRS": "EPSG:3857"
103+
}.items())])
104+
105+
r, h = self._result(self._execute_request(qs))
106+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_LayerSpace")
107+
108+
def test_wms_GetLegendGraphic_ShowFeatureCount(self):
109+
qs = "?" + "&".join(["%s=%s" % i for i in list({
110+
"MAP": urllib.parse.quote(self.projectPath),
111+
"SERVICE": "WMS",
112+
"VERSION": "1.1.1",
113+
"REQUEST": "GetLegendGraphic",
114+
"LAYER": "Country,Hello",
115+
"FORMAT": "image/png",
116+
# "HEIGHT": "500",
117+
# "WIDTH": "500",
118+
"LAYERTITLE": "TRUE",
119+
"LAYERFONTBOLD": "TRUE",
120+
"LAYERFONTSIZE": "30",
121+
"LAYERFONTFAMILY": self.fontFamily,
122+
"ITEMFONTFAMILY": self.fontFamily,
123+
"ITEMFONTBOLD": "TRUE",
124+
"ITEMFONTSIZE": "20",
125+
"SHOWFEATURECOUNT": "TRUE",
126+
"CRS": "EPSG:3857"
127+
}.items())])
128+
129+
r, h = self._result(self._execute_request(qs))
130+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ShowFeatureCount", max_size_diff=QSize(1, 1))
131+
132+
def test_getLegendGraphics_layertitle(self):
133+
"""Test that does not return an exception but an image"""
134+
135+
print("TEST FONT FAMILY: ", self.fontFamily)
136+
137+
parms = {
138+
'MAP': self.testdata_path + "test_project.qgs",
139+
'SERVICE': 'WMS',
140+
'VERSION': '1.3.0',
141+
'REQUEST': 'GetLegendGraphic',
142+
'FORMAT': 'image/png',
143+
# 'WIDTH': '20', # optional
144+
# 'HEIGHT': '20', # optional
145+
'LAYER': u'testlayer%20èé',
146+
'LAYERFONTBOLD': 'TRUE',
147+
'LAYERFONTSIZE': '30',
148+
'ITEMFONTBOLD': 'TRUE',
149+
'LAYERFONTFAMILY': self.fontFamily,
150+
'ITEMFONTFAMILY': self.fontFamily,
151+
'ITEMFONTSIZE': '20',
152+
'LAYERTITLE': 'TRUE',
153+
}
154+
qs = '?' + '&'.join([u"%s=%s" % (k, v) for k, v in parms.items()])
155+
r, h = self._result(self._execute_request(qs))
156+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_test", 250, QSize(15, 15))
157+
158+
parms = {
159+
'MAP': self.testdata_path + "test_project.qgs",
160+
'SERVICE': 'WMS',
161+
'VERSION': '1.3.0',
162+
'REQUEST': 'GetLegendGraphic',
163+
'FORMAT': 'image/png',
164+
# 'WIDTH': '20', # optional
165+
# 'HEIGHT': '20', # optional
166+
'LAYER': u'testlayer%20èé',
167+
'LAYERTITLE': 'FALSE',
168+
}
169+
qs = '?' + '&'.join([u"%s=%s" % (k, v) for k, v in parms.items()])
170+
r, h = self._result(self._execute_request(qs))
171+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_test_layertitle_false", 250, QSize(15, 15))
172+
173+
def test_getLegendGraphics_rulelabel(self):
174+
"""Test that does not return an exception but an image"""
175+
parms = {
176+
'MAP': self.testdata_path + "test_project.qgs",
177+
'SERVICE': 'WMS',
178+
'VERSION': '1.3.0',
179+
'REQUEST': 'GetLegendGraphic',
180+
'FORMAT': 'image/png',
181+
'LAYER': u'testlayer%20èé',
182+
'LAYERFONTBOLD': 'TRUE',
183+
'LAYERFONTSIZE': '30',
184+
'LAYERFONTFAMILY': self.fontFamily,
185+
'ITEMFONTFAMILY': self.fontFamily,
186+
'ITEMFONTBOLD': 'TRUE',
187+
'ITEMFONTSIZE': '20',
188+
'RULELABEL': 'TRUE',
189+
}
190+
qs = '?' + '&'.join([u"%s=%s" % (k, v) for k, v in parms.items()])
191+
r, h = self._result(self._execute_request(qs))
192+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_test", 250, QSize(15, 15))
193+
194+
parms = {
195+
'MAP': self.testdata_path + "test_project.qgs",
196+
'SERVICE': 'WMS',
197+
'VERSION': '1.3.0',
198+
'REQUEST': 'GetLegendGraphic',
199+
'FORMAT': 'image/png',
200+
'LAYER': u'testlayer%20èé',
201+
'LAYERFONTBOLD': 'TRUE',
202+
'LAYERFONTSIZE': '30',
203+
'ITEMFONTBOLD': 'TRUE',
204+
'ITEMFONTSIZE': '20',
205+
'LAYERFONTFAMILY': self.fontFamily,
206+
'ITEMFONTFAMILY': self.fontFamily,
207+
'RULELABEL': 'FALSE',
208+
}
209+
qs = '?' + '&'.join([u"%s=%s" % (k, v) for k, v in parms.items()])
210+
r, h = self._result(self._execute_request(qs))
211+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rulelabel_false", 250, QSize(15, 15))
212+
213+
def test_getLegendGraphics_rule(self):
214+
"""Test that does not return an exception but an image"""
215+
parms = {
216+
'MAP': self.testdata_path + "test_project_legend_rule.qgs",
217+
'SERVICE': 'WMS',
218+
'VERSION': '1.3.0',
219+
'REQUEST': 'GetLegendGraphic',
220+
'FORMAT': 'image/png',
221+
'LAYER': u'testlayer%20èé',
222+
'WIDTH': '20',
223+
'HEIGHT': '20',
224+
'RULE': 'rule0',
225+
}
226+
qs = '?' + '&'.join([u"%s=%s" % (k, v) for k, v in parms.items()])
227+
r, h = self._result(self._execute_request(qs))
228+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rule0", 250, QSize(15, 15))
229+
230+
parms = {
231+
'MAP': self.testdata_path + "test_project_legend_rule.qgs",
232+
'SERVICE': 'WMS',
233+
'VERSION': '1.3.0',
234+
'REQUEST': 'GetLegendGraphic',
235+
'FORMAT': 'image/png',
236+
'LAYER': u'testlayer%20èé',
237+
'WIDTH': '20',
238+
'HEIGHT': '20',
239+
'RULE': 'rule1',
240+
}
241+
qs = '?' + '&'.join([u"%s=%s" % (k, v) for k, v in parms.items()])
242+
r, h = self._result(self._execute_request(qs))
243+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rule1", 250, QSize(15, 15))
244+
245+
def test_wms_GetLegendGraphic_Basic(self):
246+
qs = "?" + "&".join(["%s=%s" % i for i in list({
247+
"MAP": urllib.parse.quote(self.projectPath),
248+
"SERVICE": "WMS",
249+
"VERSION": "1.1.1",
250+
"REQUEST": "GetLegendGraphic",
251+
"LAYER": "Country,Hello",
252+
"LAYERTITLE": "FALSE",
253+
"FORMAT": "image/png",
254+
"HEIGHT": "500",
255+
"WIDTH": "500",
256+
"CRS": "EPSG:3857"
257+
}.items())])
258+
259+
r, h = self._result(self._execute_request(qs))
260+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Basic")
261+
262+
def test_wms_GetLegendGraphic_Transparent(self):
263+
qs = "?" + "&".join(["%s=%s" % i for i in list({
264+
"MAP": urllib.parse.quote(self.projectPath),
265+
"SERVICE": "WMS",
266+
"VERSION": "1.1.1",
267+
"REQUEST": "GetLegendGraphic",
268+
"LAYER": "Country,Hello",
269+
"LAYERTITLE": "FALSE",
270+
"FORMAT": "image/png",
271+
"HEIGHT": "500",
272+
"WIDTH": "500",
273+
"CRS": "EPSG:3857",
274+
"TRANSPARENT": "TRUE"
275+
}.items())])
276+
277+
r, h = self._result(self._execute_request(qs))
278+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Transparent")
279+
280+
def test_wms_GetLegendGraphic_Background(self):
281+
qs = "?" + "&".join(["%s=%s" % i for i in list({
282+
"MAP": urllib.parse.quote(self.projectPath),
283+
"SERVICE": "WMS",
284+
"VERSION": "1.1.1",
285+
"REQUEST": "GetLegendGraphic",
286+
"LAYER": "Country,Hello",
287+
"LAYERTITLE": "FALSE",
288+
"FORMAT": "image/png",
289+
"HEIGHT": "500",
290+
"WIDTH": "500",
291+
"CRS": "EPSG:3857",
292+
"BGCOLOR": "green"
293+
}.items())])
294+
295+
r, h = self._result(self._execute_request(qs))
296+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Background")
297+
298+
qs = "?" + "&".join(["%s=%s" % i for i in list({
299+
"MAP": urllib.parse.quote(self.projectPath),
300+
"SERVICE": "WMS",
301+
"VERSION": "1.1.1",
302+
"REQUEST": "GetLegendGraphic",
303+
"LAYER": "Country,Hello",
304+
"LAYERTITLE": "FALSE",
305+
"FORMAT": "image/png",
306+
"HEIGHT": "500",
307+
"WIDTH": "500",
308+
"CRS": "EPSG:3857",
309+
"BGCOLOR": "0x008000"
310+
}.items())])
311+
312+
r, h = self._result(self._execute_request(qs))
313+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Background_Hex")
314+
315+
def test_wms_GetLegendGraphic_BoxSpace(self):
316+
qs = "?" + "&".join(["%s=%s" % i for i in list({
317+
"MAP": urllib.parse.quote(self.projectPath),
318+
"SERVICE": "WMS",
319+
"VERSION": "1.1.1",
320+
"REQUEST": "GetLegendGraphic",
321+
"LAYER": "Country,Hello",
322+
"LAYERTITLE": "FALSE",
323+
"BOXSPACE": "100",
324+
"FORMAT": "image/png",
325+
"HEIGHT": "500",
326+
"WIDTH": "500",
327+
"CRS": "EPSG:3857"
328+
}.items())])
329+
330+
r, h = self._result(self._execute_request(qs))
331+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BoxSpace")
332+
333+
def test_wms_GetLegendGraphic_SymbolSpace(self):
334+
qs = "?" + "&".join(["%s=%s" % i for i in list({
335+
"MAP": urllib.parse.quote(self.projectPath),
336+
"SERVICE": "WMS",
337+
"VERSION": "1.1.1",
338+
"REQUEST": "GetLegendGraphic",
339+
"LAYER": "Country,Hello",
340+
"LAYERTITLE": "FALSE",
341+
"SYMBOLSPACE": "100",
342+
"FORMAT": "image/png",
343+
"HEIGHT": "500",
344+
"WIDTH": "500",
345+
"CRS": "EPSG:3857"
346+
}.items())])
347+
348+
r, h = self._result(self._execute_request(qs))
349+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_SymbolSpace")
350+
351+
def test_wms_GetLegendGraphic_IconLabelSpace(self):
352+
qs = "?" + "&".join(["%s=%s" % i for i in list({
353+
"MAP": urllib.parse.quote(self.projectPath),
354+
"SERVICE": "WMS",
355+
"VERSION": "1.1.1",
356+
"REQUEST": "GetLegendGraphic",
357+
"LAYER": "Country,Hello",
358+
"LAYERTITLE": "FALSE",
359+
"ICONLABELSPACE": "100",
360+
"FORMAT": "image/png",
361+
"HEIGHT": "500",
362+
"WIDTH": "500",
363+
"CRS": "EPSG:3857"
364+
}.items())])
365+
366+
r, h = self._result(self._execute_request(qs))
367+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_IconLabelSpace")
368+
369+
def test_wms_GetLegendGraphic_SymbolSize(self):
370+
qs = "?" + "&".join(["%s=%s" % i for i in list({
371+
"MAP": urllib.parse.quote(self.projectPath),
372+
"SERVICE": "WMS",
373+
"VERSION": "1.1.1",
374+
"REQUEST": "GetLegendGraphic",
375+
"LAYER": "Country,Hello",
376+
"LAYERTITLE": "FALSE",
377+
"SYMBOLWIDTH": "50",
378+
"SYMBOLHEIGHT": "30",
379+
"FORMAT": "image/png",
380+
"HEIGHT": "500",
381+
"WIDTH": "500",
382+
"CRS": "EPSG:3857"
383+
}.items())])
384+
385+
r, h = self._result(self._execute_request(qs))
386+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_SymbolSize")
387+
388+
def test_wms_GetLegendGraphic_LayerFont(self):
389+
qs = "?" + "&".join(["%s=%s" % i for i in list({
390+
"MAP": urllib.parse.quote(self.projectPath),
391+
"SERVICE": "WMS",
392+
"VERSION": "1.1.1",
393+
"REQUEST": "GetLegendGraphic",
394+
"LAYER": "Country,Hello",
395+
"LAYERTITLE": "TRUE",
396+
"LAYERFONTBOLD": "TRUE",
397+
"LAYERFONTITALIC": "TRUE",
398+
"LAYERFONTSIZE": "30",
399+
"ITEMFONTBOLD": "TRUE",
400+
"ITEMFONTSIZE": "20",
401+
"LAYERFONTFAMILY": self.fontFamily,
402+
"ITEMFONTFAMILY": self.fontFamily,
403+
"FORMAT": "image/png",
404+
"HEIGHT": "500",
405+
"WIDTH": "500",
406+
"CRS": "EPSG:3857"
407+
}.items())])
408+
409+
r, h = self._result(self._execute_request(qs))
410+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_LayerFont", max_size_diff=QSize(1, 1))
411+
412+
def test_wms_GetLegendGraphic_ItemFont(self):
413+
qs = "?" + "&".join(["%s=%s" % i for i in list({
414+
"MAP": urllib.parse.quote(self.projectPath),
415+
"SERVICE": "WMS",
416+
"VERSION": "1.1.1",
417+
"REQUEST": "GetLegendGraphic",
418+
"LAYER": "Country,Hello",
419+
"LAYERTITLE": "TRUE",
420+
"LAYERFONTBOLD": "TRUE",
421+
"LAYERFONTSIZE": "30",
422+
"ITEMFONTBOLD": "TRUE",
423+
"ITEMFONTITALIC": "TRUE",
424+
"ITEMFONTSIZE": "20",
425+
"LAYERFONTFAMILY": self.fontFamily,
426+
"ITEMFONTFAMILY": self.fontFamily,
427+
"FORMAT": "image/png",
428+
"HEIGHT": "500",
429+
"WIDTH": "500",
430+
"CRS": "EPSG:3857"
431+
}.items())])
432+
433+
r, h = self._result(self._execute_request(qs))
434+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ItemFont", max_size_diff=QSize(1, 1))
435+
436+
def test_wms_GetLegendGraphic_BBox(self):
437+
qs = "?" + "&".join(["%s=%s" % i for i in list({
438+
"MAP": urllib.parse.quote(self.projectPath),
439+
"SERVICE": "WMS",
440+
"VERSION": "1.1.1",
441+
"REQUEST": "GetLegendGraphic",
442+
"LAYER": "Country,Hello,db_point",
443+
"LAYERTITLE": "FALSE",
444+
"FORMAT": "image/png",
445+
"HEIGHT": "500",
446+
"WIDTH": "500",
447+
"BBOX": "-151.7,-38.9,51.0,78.0",
448+
"CRS": "EPSG:4326"
449+
}.items())])
450+
451+
r, h = self._result(self._execute_request(qs))
452+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
453+
454+
def test_wms_GetLegendGraphic_BBox2(self):
455+
qs = "?" + "&".join(["%s=%s" % i for i in list({
456+
"MAP": urllib.parse.quote(self.projectPath),
457+
"SERVICE": "WMS",
458+
"VERSION": "1.1.1",
459+
"REQUEST": "GetLegendGraphic",
460+
"LAYER": "Country,Hello,db_point",
461+
"LAYERTITLE": "FALSE",
462+
"FORMAT": "image/png",
463+
"HEIGHT": "500",
464+
"WIDTH": "500",
465+
"BBOX": "-76.08,-6.4,-19.38,38.04",
466+
"SRS": "EPSG:4326"
467+
}.items())])
468+
469+
r, h = self._result(self._execute_request(qs))
470+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
471+
472+
473+
if __name__ == '__main__':
474+
unittest.main()

‎tests/src/python/test_qgsserver_wms_getmap.py

Lines changed: 873 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 394 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,394 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsServer WMS.
3+
4+
From build dir, run: ctest -R PyQgsServerWMS -V
5+
6+
7+
.. note:: This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
12+
"""
13+
__author__ = 'Alessandro Pasotti'
14+
__date__ = '25/05/2015'
15+
__copyright__ = 'Copyright 2015, The QGIS Project'
16+
# This will get replaced with a git SHA1 when you do a git archive
17+
__revision__ = '$Format:%H$'
18+
19+
import os
20+
21+
# Needed on Qt 5 so that the serialization of XML is consistent among all executions
22+
os.environ['QT_HASH_SEED'] = '1'
23+
24+
import re
25+
import urllib.request
26+
import urllib.parse
27+
import urllib.error
28+
29+
from qgis.testing import unittest
30+
from qgis.PyQt.QtCore import QSize
31+
32+
import osgeo.gdal # NOQA
33+
34+
from test_qgsserver import QgsServerTestBase
35+
from qgis.core import QgsProject
36+
37+
# Strip path and content length because path may vary
38+
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
39+
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
40+
41+
42+
class TestQgsServerWMSGetPrint(QgsServerTestBase):
43+
44+
"""QGIS Server WMS Tests for GetPrint request"""
45+
46+
def test_wms_getprint_basic(self):
47+
qs = "?" + "&".join(["%s=%s" % i for i in list({
48+
"MAP": urllib.parse.quote(self.projectPath),
49+
"SERVICE": "WMS",
50+
"VERSION": "1.1.1",
51+
"REQUEST": "GetPrint",
52+
"TEMPLATE": "layoutA4",
53+
"FORMAT": "png",
54+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
55+
"map0:LAYERS": "Country,Hello",
56+
"CRS": "EPSG:3857"
57+
}.items())])
58+
59+
r, h = self._result(self._execute_request(qs))
60+
self._img_diff_error(r, h, "WMS_GetPrint_Basic")
61+
62+
qs = "?" + "&".join(["%s=%s" % i for i in list({
63+
"MAP": urllib.parse.quote(self.projectPath),
64+
"SERVICE": "WMS",
65+
"VERSION": "1.1.1",
66+
"REQUEST": "GetPrint",
67+
"TEMPLATE": "layoutA4",
68+
"FORMAT": "png",
69+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
70+
"LAYERS": "Country,Hello",
71+
"CRS": "EPSG:3857"
72+
}.items())])
73+
74+
r, h = self._result(self._execute_request(qs))
75+
self._img_diff_error(r, h, "WMS_GetPrint_Basic")
76+
77+
qs = "?" + "&".join(["%s=%s" % i for i in list({
78+
"MAP": urllib.parse.quote(self.projectPath),
79+
"SERVICE": "WMS",
80+
"VERSION": "1.1.1",
81+
"REQUEST": "GetPrint",
82+
"TEMPLATE": "layoutA4",
83+
"FORMAT": "png",
84+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
85+
"map0:LAYERS": "Country,Hello",
86+
"LAYERS": "Country,Hello",
87+
"CRS": "EPSG:3857"
88+
}.items())])
89+
90+
r, h = self._result(self._execute_request(qs))
91+
self._img_diff_error(r, h, "WMS_GetPrint_Basic")
92+
93+
def test_wms_getprint_style(self):
94+
# default style
95+
qs = "?" + "&".join(["%s=%s" % i for i in list({
96+
"MAP": urllib.parse.quote(self.projectPath),
97+
"SERVICE": "WMS",
98+
"VERSION": "1.1.1",
99+
"REQUEST": "GetPrint",
100+
"TEMPLATE": "layoutA4",
101+
"FORMAT": "png",
102+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
103+
"map0:LAYERS": "Country_Labels",
104+
"CRS": "EPSG:3857"
105+
}.items())])
106+
107+
r, h = self._result(self._execute_request(qs))
108+
assert h.get("Content-Type").startswith('image'), r
109+
self._img_diff_error(r, h, "WMS_GetPrint_StyleDefault")
110+
111+
# custom style
112+
qs = "?" + "&".join(["%s=%s" % i for i in list({
113+
"MAP": urllib.parse.quote(self.projectPath),
114+
"SERVICE": "WMS",
115+
"VERSION": "1.1.1",
116+
"REQUEST": "GetPrint",
117+
"TEMPLATE": "layoutA4",
118+
"FORMAT": "png",
119+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
120+
"map0:LAYERS": "Country_Labels",
121+
"map0:STYLES": "custom",
122+
"CRS": "EPSG:3857"
123+
}.items())])
124+
125+
r, h = self._result(self._execute_request(qs))
126+
self._img_diff_error(r, h, "WMS_GetPrint_StyleCustom")
127+
128+
# default style
129+
qs = "?" + "&".join(["%s=%s" % i for i in list({
130+
"MAP": urllib.parse.quote(self.projectPath),
131+
"SERVICE": "WMS",
132+
"VERSION": "1.1.1",
133+
"REQUEST": "GetPrint",
134+
"TEMPLATE": "layoutA4",
135+
"FORMAT": "png",
136+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
137+
"LAYERS": "Country_Labels",
138+
"CRS": "EPSG:3857"
139+
}.items())])
140+
141+
r, h = self._result(self._execute_request(qs))
142+
self._img_diff_error(r, h, "WMS_GetPrint_StyleDefault")
143+
144+
# custom style
145+
qs = "?" + "&".join(["%s=%s" % i for i in list({
146+
"MAP": urllib.parse.quote(self.projectPath),
147+
"SERVICE": "WMS",
148+
"VERSION": "1.1.1",
149+
"REQUEST": "GetPrint",
150+
"TEMPLATE": "layoutA4",
151+
"FORMAT": "png",
152+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
153+
"LAYERS": "Country_Labels",
154+
"STYLES": "custom",
155+
"CRS": "EPSG:3857"
156+
}.items())])
157+
158+
r, h = self._result(self._execute_request(qs))
159+
self._img_diff_error(r, h, "WMS_GetPrint_StyleCustom")
160+
161+
# default style
162+
qs = "?" + "&".join(["%s=%s" % i for i in list({
163+
"MAP": urllib.parse.quote(self.projectPath),
164+
"SERVICE": "WMS",
165+
"VERSION": "1.1.1",
166+
"REQUEST": "GetPrint",
167+
"TEMPLATE": "layoutA4",
168+
"FORMAT": "png",
169+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
170+
"map0:LAYERS": "Country_Labels",
171+
"LAYERS": "Country_Labels",
172+
"CRS": "EPSG:3857"
173+
}.items())])
174+
175+
r, h = self._result(self._execute_request(qs))
176+
self._img_diff_error(r, h, "WMS_GetPrint_StyleDefault")
177+
178+
# custom style
179+
qs = "?" + "&".join(["%s=%s" % i for i in list({
180+
"MAP": urllib.parse.quote(self.projectPath),
181+
"SERVICE": "WMS",
182+
"VERSION": "1.1.1",
183+
"REQUEST": "GetPrint",
184+
"TEMPLATE": "layoutA4",
185+
"FORMAT": "png",
186+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
187+
"map0:LAYERS": "Country_Labels",
188+
"map0:STYLES": "custom",
189+
"LAYERS": "Country_Labels",
190+
"CRS": "EPSG:3857"
191+
}.items())])
192+
193+
r, h = self._result(self._execute_request(qs))
194+
self._img_diff_error(r, h, "WMS_GetPrint_StyleCustom")
195+
196+
def test_wms_getprint_legend(self):
197+
qs = "?" + "&".join(["%s=%s" % i for i in list({
198+
"MAP": urllib.parse.quote(self.projectPath),
199+
"SERVICE": "WMS",
200+
"VERSION": "1.1.1",
201+
"REQUEST": "GetPrint",
202+
"TEMPLATE": "layoutA4copy",
203+
"FORMAT": "png",
204+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
205+
"map0:LAYERS": "Country,Hello",
206+
"CRS": "EPSG:3857"
207+
}.items())])
208+
209+
r, h = self._result(self._execute_request(qs))
210+
self._img_diff_error(r, h, "WMS_GetPrint_Legend")
211+
212+
def test_wms_getprint_srs(self):
213+
qs = "?" + "&".join(["%s=%s" % i for i in list({
214+
"MAP": urllib.parse.quote(self.projectPath),
215+
"SERVICE": "WMS",
216+
"VERSION": "1.1.1",
217+
"REQUEST": "GetPrint",
218+
"TEMPLATE": "layoutA4",
219+
"FORMAT": "png",
220+
"map0:EXTENT": "-309.015,-133.011,312.179,133.949",
221+
"map0:LAYERS": "Country,Hello",
222+
"CRS": "EPSG:4326"
223+
}.items())])
224+
225+
r, h = self._result(self._execute_request(qs))
226+
self._img_diff_error(r, h, "WMS_GetPrint_SRS")
227+
228+
def test_wms_getprint_scale(self):
229+
qs = "?" + "&".join(["%s=%s" % i for i in list({
230+
"MAP": urllib.parse.quote(self.projectPath),
231+
"SERVICE": "WMS",
232+
"VERSION": "1.1.1",
233+
"REQUEST": "GetPrint",
234+
"TEMPLATE": "layoutA4",
235+
"FORMAT": "png",
236+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
237+
"map0:LAYERS": "Country,Hello",
238+
"map0:SCALE": "36293562",
239+
"CRS": "EPSG:3857"
240+
}.items())])
241+
242+
r, h = self._result(self._execute_request(qs))
243+
self._img_diff_error(r, h, "WMS_GetPrint_Scale")
244+
245+
def test_wms_getprint_grid(self):
246+
qs = "?" + "&".join(["%s=%s" % i for i in list({
247+
"MAP": urllib.parse.quote(self.projectPath),
248+
"SERVICE": "WMS",
249+
"VERSION": "1.1.1",
250+
"REQUEST": "GetPrint",
251+
"TEMPLATE": "layoutA4",
252+
"FORMAT": "png",
253+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
254+
"map0:LAYERS": "Country,Hello",
255+
"map0:GRID_INTERVAL_X": "1000000",
256+
"map0:GRID_INTERVAL_Y": "2000000",
257+
"CRS": "EPSG:3857"
258+
}.items())])
259+
260+
r, h = self._result(self._execute_request(qs))
261+
self._img_diff_error(r, h, "WMS_GetPrint_Grid")
262+
263+
def test_wms_getprint_rotation(self):
264+
qs = "?" + "&".join(["%s=%s" % i for i in list({
265+
"MAP": urllib.parse.quote(self.projectPath),
266+
"SERVICE": "WMS",
267+
"VERSION": "1.1.1",
268+
"REQUEST": "GetPrint",
269+
"TEMPLATE": "layoutA4",
270+
"FORMAT": "png",
271+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
272+
"map0:LAYERS": "Country,Hello",
273+
"map0:ROTATION": "45",
274+
"CRS": "EPSG:3857"
275+
}.items())])
276+
277+
r, h = self._result(self._execute_request(qs))
278+
self._img_diff_error(r, h, "WMS_GetPrint_Rotation")
279+
280+
def test_wms_getprint_selection(self):
281+
qs = "?" + "&".join(["%s=%s" % i for i in list({
282+
"MAP": urllib.parse.quote(self.projectPath),
283+
"SERVICE": "WMS",
284+
"VERSION": "1.1.1",
285+
"REQUEST": "GetPrint",
286+
"TEMPLATE": "layoutA4",
287+
"FORMAT": "png",
288+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
289+
"map0:LAYERS": "Country,Hello",
290+
"CRS": "EPSG:3857",
291+
"SELECTION": "Country: 4"
292+
}.items())])
293+
294+
r, h = self._result(self._execute_request(qs))
295+
self._img_diff_error(r, h, "WMS_GetPrint_Selection")
296+
297+
def test_wms_getprint_opacity(self):
298+
qs = "?" + "&".join(["%s=%s" % i for i in list({
299+
"MAP": urllib.parse.quote(self.projectPath),
300+
"SERVICE": "WMS",
301+
"VERSION": "1.1.1",
302+
"REQUEST": "GetPrint",
303+
"TEMPLATE": "layoutA4",
304+
"FORMAT": "png",
305+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
306+
"map0:LAYERS": "Country,Hello",
307+
"CRS": "EPSG:3857",
308+
"SELECTION": "Country: 4",
309+
"LAYERS": "Country,Hello",
310+
"OPACITIES": "125,125"
311+
}.items())])
312+
313+
r, h = self._result(self._execute_request(qs))
314+
self._img_diff_error(r, h, "WMS_GetPrint_Opacity")
315+
316+
qs = "?" + "&".join(["%s=%s" % i for i in list({
317+
"MAP": urllib.parse.quote(self.projectPath),
318+
"SERVICE": "WMS",
319+
"VERSION": "1.1.1",
320+
"REQUEST": "GetPrint",
321+
"TEMPLATE": "layoutA4",
322+
"FORMAT": "png",
323+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
324+
"map0:LAYERS": "Country,Hello",
325+
"CRS": "EPSG:3857",
326+
"SELECTION": "Country: 4",
327+
"LAYERS": "Country,Hello",
328+
"OPACITIES": "125%2C125"
329+
}.items())])
330+
331+
r, h = self._result(self._execute_request(qs))
332+
self._img_diff_error(r, h, "WMS_GetPrint_Opacity")
333+
334+
def test_wms_getprint_highlight(self):
335+
# default style
336+
qs = "?" + "&".join(["%s=%s" % i for i in list({
337+
"MAP": urllib.parse.quote(self.projectPath),
338+
"SERVICE": "WMS",
339+
"VERSION": "1.1.1",
340+
"REQUEST": "GetPrint",
341+
"TEMPLATE": "layoutA4",
342+
"FORMAT": "png",
343+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
344+
"map0:LAYERS": "Country_Labels",
345+
"map0:HIGHLIGHT_GEOM": "POLYGON((-15000000 10000000, -15000000 6110620, 2500000 6110620, 2500000 10000000, -15000000 10000000))",
346+
"map0:HIGHLIGHT_SYMBOL": "<StyledLayerDescriptor><UserStyle><Name>Highlight</Name><FeatureTypeStyle><Rule><Name>Symbol</Name><LineSymbolizer><Stroke><SvgParameter name=\"stroke\">%23ea1173</SvgParameter><SvgParameter name=\"stroke-opacity\">1</SvgParameter><SvgParameter name=\"stroke-width\">1.6</SvgParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></StyledLayerDescriptor>",
347+
"map0:HIGHLIGHT_LABELSTRING": "Highlight Layer!",
348+
"map0:HIGHLIGHT_LABELSIZE": "16",
349+
"map0:HIGHLIGHT_LABELCOLOR": "%2300FF0000",
350+
"map0:HIGHLIGHT_LABELBUFFERCOLOR": "%232300FF00",
351+
"map0:HIGHLIGHT_LABELBUFFERSIZE": "1.5",
352+
"CRS": "EPSG:3857"
353+
}.items())])
354+
355+
r, h = self._result(self._execute_request(qs))
356+
assert h.get("Content-Type").startswith('image'), r
357+
self._img_diff_error(r, h, "WMS_GetPrint_Highlight")
358+
359+
def test_wms_getprint_label(self):
360+
qs = "?" + "&".join(["%s=%s" % i for i in list({
361+
"MAP": urllib.parse.quote(self.projectPath),
362+
"SERVICE": "WMS",
363+
"VERSION": "1.1.1",
364+
"REQUEST": "GetPrint",
365+
"TEMPLATE": "layoutA4",
366+
"FORMAT": "png",
367+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
368+
"map0:LAYERS": "Country,Hello",
369+
"CRS": "EPSG:3857",
370+
"IDTEXTBOX": "Updated QGIS composer label"
371+
}.items())])
372+
373+
r, h = self._result(self._execute_request(qs))
374+
self._img_diff_error(r, h, "WMS_GetPrint_LabelUpdated")
375+
376+
qs = "?" + "&".join(["%s=%s" % i for i in list({
377+
"MAP": urllib.parse.quote(self.projectPath),
378+
"SERVICE": "WMS",
379+
"VERSION": "1.1.1",
380+
"REQUEST": "GetPrint",
381+
"TEMPLATE": "layoutA4",
382+
"FORMAT": "png",
383+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
384+
"map0:LAYERS": "Country,Hello",
385+
"CRS": "EPSG:3857",
386+
"IDTEXTBOX": ""
387+
}.items())])
388+
389+
r, h = self._result(self._execute_request(qs))
390+
self._img_diff_error(r, h, "WMS_GetPrint_LabelRemoved")
391+
392+
393+
if __name__ == '__main__':
394+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.