-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Server][Feature][needs-docs] Create WMTS service Tests
- Loading branch information
Showing
10 changed files
with
2,478 additions
and
2,350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsServer WFS. | ||
From build dir, run: ctest -R PyQgsServerWFS -V | ||
.. 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__ = 'René-Luc Dhont' | ||
__date__ = '19/09/2017' | ||
__copyright__ = 'Copyright 2017, 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 re | ||
import urllib.request | ||
import urllib.parse | ||
import urllib.error | ||
|
||
from qgis.server import QgsServerRequest | ||
|
||
from qgis.testing import unittest | ||
from qgis.PyQt.QtCore import QSize | ||
|
||
import osgeo.gdal # NOQA | ||
|
||
from test_qgsserver import QgsServerTestBase | ||
|
||
# Strip path and content length because path may vary | ||
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+|timeStamp="[^"]+"' | ||
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+' | ||
|
||
|
||
class TestQgsServerWMTS(QgsServerTestBase): | ||
|
||
"""QGIS Server WMTS Tests""" | ||
|
||
def wmts_request_compare(self, request, version='', extra_query_string='', reference_base_name=None): | ||
#project = self.testdata_path + "test_project_wfs.qgs" | ||
project = self.projectGroupsPath | ||
assert os.path.exists(project), "Project file not found: " + project | ||
|
||
query_string = '?MAP=%s&SERVICE=WMTS&REQUEST=%s' % (urllib.parse.quote(project), request) | ||
if version: | ||
query_string += '&VERSION=%s' % version | ||
|
||
if extra_query_string: | ||
query_string += '&%s' % extra_query_string | ||
|
||
header, body = self._execute_request(query_string) | ||
self.assert_headers(header, body) | ||
response = header + body | ||
|
||
if reference_base_name is not None: | ||
reference_name = reference_base_name | ||
else: | ||
reference_name = 'wmts_' + request.lower() | ||
|
||
reference_name += '.txt' | ||
|
||
reference_path = self.testdata_path + reference_name | ||
|
||
self.store_reference(reference_path, response) | ||
f = open(reference_path, 'rb') | ||
expected = f.read() | ||
f.close() | ||
response = re.sub(RE_STRIP_UNCHECKABLE, b'', response) | ||
expected = re.sub(RE_STRIP_UNCHECKABLE, b'', expected) | ||
|
||
self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s" % (query_string, request)) | ||
|
||
def test_project_wmts(self): | ||
"""Test some WMTS request""" | ||
for request in ('GetCapabilities',): | ||
self.wmts_request_compare(request) | ||
#self.wmts_request_compare(request, '1.0.0') | ||
|
||
def test_wmts_gettile(self): | ||
# Testing project WMTS layer | ||
qs = "?" + "&".join(["%s=%s" % i for i in list({ | ||
"MAP": urllib.parse.quote(self.projectGroupsPath), | ||
"SERVICE": "WMTS", | ||
"VERSION": "1.0.0", | ||
"REQUEST": "GetTile", | ||
"LAYER": "QGIS Server Hello World", | ||
"STYLE": "", | ||
"TILEMATRIXSET": "EPSG:3857", | ||
"TILEMATRIX": "0", | ||
"TILEROW": "0", | ||
"TILECOL": "0", | ||
"FORMAT": "image/png" | ||
}.items())]) | ||
|
||
r, h = self._result(self._execute_request(qs)) | ||
self._img_diff_error(r, h, "WMTS_GetTile_Project_3857_0", 20000) | ||
|
||
qs = "?" + "&".join(["%s=%s" % i for i in list({ | ||
"MAP": urllib.parse.quote(self.projectGroupsPath), | ||
"SERVICE": "WMTS", | ||
"VERSION": "1.0.0", | ||
"REQUEST": "GetTile", | ||
"LAYER": "QGIS Server Hello World", | ||
"STYLE": "", | ||
"TILEMATRIXSET": "EPSG:4326", | ||
"TILEMATRIX": "0", | ||
"TILEROW": "0", | ||
"TILECOL": "0", | ||
"FORMAT": "image/png" | ||
}.items())]) | ||
|
||
r, h = self._result(self._execute_request(qs)) | ||
self._img_diff_error(r, h, "WMTS_GetTile_Project_4326_0", 20000) | ||
|
||
# Testing group WMTS layer | ||
qs = "?" + "&".join(["%s=%s" % i for i in list({ | ||
"MAP": urllib.parse.quote(self.projectGroupsPath), | ||
"SERVICE": "WMTS", | ||
"VERSION": "1.0.0", | ||
"REQUEST": "GetTile", | ||
"LAYER": "CountryGroup", | ||
"STYLE": "", | ||
"TILEMATRIXSET": "EPSG:3857", | ||
"TILEMATRIX": "0", | ||
"TILEROW": "0", | ||
"TILECOL": "0", | ||
"FORMAT": "image/png" | ||
}.items())]) | ||
|
||
r, h = self._result(self._execute_request(qs)) | ||
self._img_diff_error(r, h, "WMTS_GetTile_CountryGroup_3857_0", 20000) | ||
|
||
qs = "?" + "&".join(["%s=%s" % i for i in list({ | ||
"MAP": urllib.parse.quote(self.projectGroupsPath), | ||
"SERVICE": "WMTS", | ||
"VERSION": "1.0.0", | ||
"REQUEST": "GetTile", | ||
"LAYER": "CountryGroup", | ||
"STYLE": "", | ||
"TILEMATRIXSET": "EPSG:4326", | ||
"TILEMATRIX": "0", | ||
"TILEROW": "0", | ||
"TILECOL": "0", | ||
"FORMAT": "image/png" | ||
}.items())]) | ||
|
||
r, h = self._result(self._execute_request(qs)) | ||
self._img_diff_error(r, h, "WMTS_GetTile_CountryGroup_4326_0", 20000) | ||
|
||
# Testing QgsMapLayer WMTS layer | ||
qs = "?" + "&".join(["%s=%s" % i for i in list({ | ||
"MAP": urllib.parse.quote(self.projectGroupsPath), | ||
"SERVICE": "WMTS", | ||
"VERSION": "1.0.0", | ||
"REQUEST": "GetTile", | ||
"LAYER": "Hello", | ||
"STYLE": "", | ||
"TILEMATRIXSET": "EPSG:3857", | ||
"TILEMATRIX": "0", | ||
"TILEROW": "0", | ||
"TILECOL": "0", | ||
"FORMAT": "image/png" | ||
}.items())]) | ||
|
||
r, h = self._result(self._execute_request(qs)) | ||
self._img_diff_error(r, h, "WMTS_GetTile_Hello_3857_0", 20000) | ||
|
||
qs = "?" + "&".join(["%s=%s" % i for i in list({ | ||
"MAP": urllib.parse.quote(self.projectGroupsPath), | ||
"SERVICE": "WMTS", | ||
"VERSION": "1.0.0", | ||
"REQUEST": "GetTile", | ||
"LAYER": "Hello", | ||
"STYLE": "", | ||
"TILEMATRIXSET": "EPSG:4326", | ||
"TILEMATRIX": "0", | ||
"TILEROW": "0", | ||
"TILECOL": "0", | ||
"FORMAT": "image/png" | ||
}.items())]) | ||
|
||
r, h = self._result(self._execute_request(qs)) | ||
self._img_diff_error(r, h, "WMTS_GetTile_Hello_4326_0", 20000) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Binary file added
BIN
+25.2 KB
...is_server/WMTS_GetTile_CountryGroup_3857_0/WMTS_GetTile_CountryGroup_3857_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.9 KB
...is_server/WMTS_GetTile_CountryGroup_4326_0/WMTS_GetTile_CountryGroup_4326_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
...trol_images/qgis_server/WMTS_GetTile_Hello_3857_0/WMTS_GetTile_Hello_3857_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...trol_images/qgis_server/WMTS_GetTile_Hello_4326_0/WMTS_GetTile_Hello_4326_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.3 KB
..._images/qgis_server/WMTS_GetTile_Project_3857_0/WMTS_GetTile_Project_3857_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.2 KB
..._images/qgis_server/WMTS_GetTile_Project_4326_0/WMTS_GetTile_Project_4326_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.