Skip to content

Commit 385de9d

Browse files
committedAug 20, 2018
[Server][Feature][needs-docs] Create WMTS service Tests
1 parent 50766ef commit 385de9d

File tree

10 files changed

+2478
-2350
lines changed

10 files changed

+2478
-2350
lines changed
 

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ IF (WITH_SERVER)
269269
ADD_PYTHON_TEST(PyQgsServerAccessControlWCS test_qgsserver_accesscontrol_wcs.py)
270270
ADD_PYTHON_TEST(PyQgsServerAccessControlWFSTransactional test_qgsserver_accesscontrol_wfs_transactional.py)
271271
ADD_PYTHON_TEST(PyQgsServerCacheManager test_qgsserver_cachemanager.py)
272+
ADD_PYTHON_TEST(PyQgsServerWMTS test_qgsserver_wmts.py)
272273
ADD_PYTHON_TEST(PyQgsServerWFS test_qgsserver_wfs.py)
273274
ADD_PYTHON_TEST(PyQgsServerWFST test_qgsserver_wfst.py)
274275
ADD_PYTHON_TEST(PyQgsOfflineEditingWFS test_offline_editing_wfs.py)
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsServer WFS.
3+
4+
From build dir, run: ctest -R PyQgsServerWFS -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__ = 'René-Luc Dhont'
14+
__date__ = '19/09/2017'
15+
__copyright__ = 'Copyright 2017, 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.server import QgsServerRequest
30+
31+
from qgis.testing import unittest
32+
from qgis.PyQt.QtCore import QSize
33+
34+
import osgeo.gdal # NOQA
35+
36+
from test_qgsserver import QgsServerTestBase
37+
38+
# Strip path and content length because path may vary
39+
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+|timeStamp="[^"]+"'
40+
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
41+
42+
43+
class TestQgsServerWMTS(QgsServerTestBase):
44+
45+
"""QGIS Server WMTS Tests"""
46+
47+
def wmts_request_compare(self, request, version='', extra_query_string='', reference_base_name=None):
48+
#project = self.testdata_path + "test_project_wfs.qgs"
49+
project = self.projectGroupsPath
50+
assert os.path.exists(project), "Project file not found: " + project
51+
52+
query_string = '?MAP=%s&SERVICE=WMTS&REQUEST=%s' % (urllib.parse.quote(project), request)
53+
if version:
54+
query_string += '&VERSION=%s' % version
55+
56+
if extra_query_string:
57+
query_string += '&%s' % extra_query_string
58+
59+
header, body = self._execute_request(query_string)
60+
self.assert_headers(header, body)
61+
response = header + body
62+
63+
if reference_base_name is not None:
64+
reference_name = reference_base_name
65+
else:
66+
reference_name = 'wmts_' + request.lower()
67+
68+
reference_name += '.txt'
69+
70+
reference_path = self.testdata_path + reference_name
71+
72+
self.store_reference(reference_path, response)
73+
f = open(reference_path, 'rb')
74+
expected = f.read()
75+
f.close()
76+
response = re.sub(RE_STRIP_UNCHECKABLE, b'', response)
77+
expected = re.sub(RE_STRIP_UNCHECKABLE, b'', expected)
78+
79+
self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s" % (query_string, request))
80+
81+
def test_project_wmts(self):
82+
"""Test some WMTS request"""
83+
for request in ('GetCapabilities',):
84+
self.wmts_request_compare(request)
85+
#self.wmts_request_compare(request, '1.0.0')
86+
87+
def test_wmts_gettile(self):
88+
# Testing project WMTS layer
89+
qs = "?" + "&".join(["%s=%s" % i for i in list({
90+
"MAP": urllib.parse.quote(self.projectGroupsPath),
91+
"SERVICE": "WMTS",
92+
"VERSION": "1.0.0",
93+
"REQUEST": "GetTile",
94+
"LAYER": "QGIS Server Hello World",
95+
"STYLE": "",
96+
"TILEMATRIXSET": "EPSG:3857",
97+
"TILEMATRIX": "0",
98+
"TILEROW": "0",
99+
"TILECOL": "0",
100+
"FORMAT": "image/png"
101+
}.items())])
102+
103+
r, h = self._result(self._execute_request(qs))
104+
self._img_diff_error(r, h, "WMTS_GetTile_Project_3857_0", 20000)
105+
106+
qs = "?" + "&".join(["%s=%s" % i for i in list({
107+
"MAP": urllib.parse.quote(self.projectGroupsPath),
108+
"SERVICE": "WMTS",
109+
"VERSION": "1.0.0",
110+
"REQUEST": "GetTile",
111+
"LAYER": "QGIS Server Hello World",
112+
"STYLE": "",
113+
"TILEMATRIXSET": "EPSG:4326",
114+
"TILEMATRIX": "0",
115+
"TILEROW": "0",
116+
"TILECOL": "0",
117+
"FORMAT": "image/png"
118+
}.items())])
119+
120+
r, h = self._result(self._execute_request(qs))
121+
self._img_diff_error(r, h, "WMTS_GetTile_Project_4326_0", 20000)
122+
123+
# Testing group WMTS layer
124+
qs = "?" + "&".join(["%s=%s" % i for i in list({
125+
"MAP": urllib.parse.quote(self.projectGroupsPath),
126+
"SERVICE": "WMTS",
127+
"VERSION": "1.0.0",
128+
"REQUEST": "GetTile",
129+
"LAYER": "CountryGroup",
130+
"STYLE": "",
131+
"TILEMATRIXSET": "EPSG:3857",
132+
"TILEMATRIX": "0",
133+
"TILEROW": "0",
134+
"TILECOL": "0",
135+
"FORMAT": "image/png"
136+
}.items())])
137+
138+
r, h = self._result(self._execute_request(qs))
139+
self._img_diff_error(r, h, "WMTS_GetTile_CountryGroup_3857_0", 20000)
140+
141+
qs = "?" + "&".join(["%s=%s" % i for i in list({
142+
"MAP": urllib.parse.quote(self.projectGroupsPath),
143+
"SERVICE": "WMTS",
144+
"VERSION": "1.0.0",
145+
"REQUEST": "GetTile",
146+
"LAYER": "CountryGroup",
147+
"STYLE": "",
148+
"TILEMATRIXSET": "EPSG:4326",
149+
"TILEMATRIX": "0",
150+
"TILEROW": "0",
151+
"TILECOL": "0",
152+
"FORMAT": "image/png"
153+
}.items())])
154+
155+
r, h = self._result(self._execute_request(qs))
156+
self._img_diff_error(r, h, "WMTS_GetTile_CountryGroup_4326_0", 20000)
157+
158+
# Testing QgsMapLayer WMTS layer
159+
qs = "?" + "&".join(["%s=%s" % i for i in list({
160+
"MAP": urllib.parse.quote(self.projectGroupsPath),
161+
"SERVICE": "WMTS",
162+
"VERSION": "1.0.0",
163+
"REQUEST": "GetTile",
164+
"LAYER": "Hello",
165+
"STYLE": "",
166+
"TILEMATRIXSET": "EPSG:3857",
167+
"TILEMATRIX": "0",
168+
"TILEROW": "0",
169+
"TILECOL": "0",
170+
"FORMAT": "image/png"
171+
}.items())])
172+
173+
r, h = self._result(self._execute_request(qs))
174+
self._img_diff_error(r, h, "WMTS_GetTile_Hello_3857_0", 20000)
175+
176+
qs = "?" + "&".join(["%s=%s" % i for i in list({
177+
"MAP": urllib.parse.quote(self.projectGroupsPath),
178+
"SERVICE": "WMTS",
179+
"VERSION": "1.0.0",
180+
"REQUEST": "GetTile",
181+
"LAYER": "Hello",
182+
"STYLE": "",
183+
"TILEMATRIXSET": "EPSG:4326",
184+
"TILEMATRIX": "0",
185+
"TILEROW": "0",
186+
"TILECOL": "0",
187+
"FORMAT": "image/png"
188+
}.items())])
189+
190+
r, h = self._result(self._execute_request(qs))
191+
self._img_diff_error(r, h, "WMTS_GetTile_Hello_4326_0", 20000)
192+
193+
194+
if __name__ == '__main__':
195+
unittest.main()

‎tests/testdata/qgis_server/wmts_getcapabilities.txt

Lines changed: 1373 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/testdata/qgis_server_accesscontrol/project_groups.qgs

Lines changed: 909 additions & 2350 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.