Skip to content

Commit 273d7ec

Browse files
sbrunnergithub-actions[bot]
authored andcommitted
Add missing tests on SERVICE_URL environment variables
1 parent e9a065f commit 273d7ec

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

tests/src/python/test_qgsserver.py

-3
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,6 @@ def test_wcs_getcapabilities_url(self):
496496
item_found = False
497497
for item in str(r).split("\\n"):
498498
if "OnlineResource" in item:
499-
print(item)
500-
print(header_name)
501-
print(header_value)
502499
self.assertEqual(header_value in item, True)
503500
item_found = True
504501
self.assertTrue(item_found)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
QGIS Unit tests for QgsServer with service URL defined in the environment variables
4+
"""
5+
__author__ = 'Stéphane Brunner'
6+
__date__ = '12/01/2021'
7+
__copyright__ = 'Copyright 2021, The QGIS Project'
8+
9+
import os
10+
11+
# Deterministic XML
12+
os.environ['QT_HASH_SEED'] = '1'
13+
14+
import urllib.request
15+
import urllib.parse
16+
import urllib.error
17+
18+
from qgis.server import QgsServer
19+
from qgis.core import QgsFontUtils
20+
from qgis.testing import unittest, start_app
21+
from utilities import unitTestDataPath
22+
23+
24+
start_app()
25+
26+
27+
class TestQgsServerServiceUrlEnv(unittest.TestCase):
28+
29+
def setUp(self):
30+
"""Create the server instance"""
31+
self.fontFamily = QgsFontUtils.standardTestFontFamily()
32+
QgsFontUtils.loadStandardTestFonts(['All'])
33+
34+
self.testdata_path = unitTestDataPath('qgis_server') + '/'
35+
project = os.path.join(self.testdata_path, "test_project_without_urls.qgs")
36+
37+
del os.environ['QUERY_STRING']
38+
os.environ['QGIS_PROJECT_FILE'] = project
39+
# Disable landing page API to test standard legacy XML responses in case of errors
40+
os.environ["QGIS_SERVER_DISABLED_APIS"] = "Landing Page"
41+
42+
self.server = QgsServer()
43+
44+
def tearDown(self):
45+
"""Cleanup env"""
46+
47+
super().tearDown()
48+
for env in ["QGIS_SERVER_DISABLED_APIS", "QGIS_PROJECT_FILE"]:
49+
if env in os.environ:
50+
del os.environ[env]
51+
52+
"""Tests container"""
53+
54+
def test_getcapabilities_url(self):
55+
56+
# Service URL in environment
57+
for env_name, env_value, service in (
58+
("QGIS_SERVER_SERVICE_URL", "http://test1", "WMS"),
59+
("QGIS_SERVER_WMS_SERVICE_URL", "http://test2", "WMS")
60+
("QGIS_SERVER_SERVICE_URL", "http://test3", "WFS", "href="),
61+
("QGIS_SERVER_WFS_SERVICE_URL", "http://test4", "WFS", "href=")
62+
("QGIS_SERVER_SERVICE_URL", "http://test5", "WCS"),
63+
("QGIS_SERVER_WCS_SERVICE_URL", "http://test6", "WCS")
64+
("QGIS_SERVER_SERVICE_URL", "http://test7", "WMTS"),
65+
("QGIS_SERVER_WMTS_SERVICE_URL", "http://test8", "WMTS")
66+
):
67+
try:
68+
os.environ[env_name] = env_value
69+
qs = "?" + "&".join(["%s=%s" % i for i in list({
70+
"SERVICE": service,
71+
"REQUEST": "GetCapabilities",
72+
}.items())])
73+
74+
r, _ = self._result(self._execute_request(qs))
75+
76+
item_found = False
77+
for item in str(r).split("\\n"):
78+
if "href=" in item:
79+
self.assertEqual(env_value in item, True)
80+
item_found = True
81+
self.assertTrue(item_found)
82+
finally:
83+
del os.environ[env_name]
84+
85+
86+
if __name__ == '__main__':
87+
unittest.main()

0 commit comments

Comments
 (0)