Skip to content

Commit

Permalink
[Server][Feature][needs-docs] Create WMTS service Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Aug 20, 2018
1 parent 50766ef commit 385de9d
Show file tree
Hide file tree
Showing 10 changed files with 2,478 additions and 2,350 deletions.
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ IF (WITH_SERVER)
ADD_PYTHON_TEST(PyQgsServerAccessControlWCS test_qgsserver_accesscontrol_wcs.py)
ADD_PYTHON_TEST(PyQgsServerAccessControlWFSTransactional test_qgsserver_accesscontrol_wfs_transactional.py)
ADD_PYTHON_TEST(PyQgsServerCacheManager test_qgsserver_cachemanager.py)
ADD_PYTHON_TEST(PyQgsServerWMTS test_qgsserver_wmts.py)
ADD_PYTHON_TEST(PyQgsServerWFS test_qgsserver_wfs.py)
ADD_PYTHON_TEST(PyQgsServerWFST test_qgsserver_wfst.py)
ADD_PYTHON_TEST(PyQgsOfflineEditingWFS test_offline_editing_wfs.py)
Expand Down
195 changes: 195 additions & 0 deletions tests/src/python/test_qgsserver_wmts.py
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 385de9d

Please sign in to comment.