|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsServer MaxHeight and MaxWidth Override Options. |
| 3 | +
|
| 4 | +From build dir, run: ctest -R PyQgsServerGetMapSize -V |
| 5 | +
|
| 6 | +.. note:: This test needs env vars to be set before the server is |
| 7 | + configured for the first time, for this |
| 8 | + reason it cannot run as a test case of another server |
| 9 | + test. |
| 10 | +
|
| 11 | +.. note:: This program is free software; you can redistribute it and/or modify |
| 12 | +it under the terms of the GNU General Public License as published by |
| 13 | +the Free Software Foundation; either version 2 of the License, or |
| 14 | +(at your option) any later version. |
| 15 | +
|
| 16 | +""" |
| 17 | +__author__ = 'Marco Bernasocchi' |
| 18 | +__date__ = '01/04/2019' |
| 19 | +__copyright__ = 'Copyright 2019, The QGIS Project' |
| 20 | +# This will get replaced with a git SHA1 when you do a git archive |
| 21 | +__revision__ = '$Format:%H$' |
| 22 | + |
| 23 | +import os |
| 24 | + |
| 25 | +# Needed on Qt 5 so that the serialization of XML is consistent among all |
| 26 | +# executions |
| 27 | +os.environ['QT_HASH_SEED'] = '1' |
| 28 | + |
| 29 | + |
| 30 | +import urllib.parse |
| 31 | + |
| 32 | +from qgis.testing import unittest |
| 33 | + |
| 34 | +from test_qgsserver import QgsServerTestBase |
| 35 | + |
| 36 | + |
| 37 | +class TestQgsServerWMSGetMapSizeProject(QgsServerTestBase): |
| 38 | + """QGIS Server WMS Tests for GetFeatureInfo request""" |
| 39 | + |
| 40 | + # Set to True to re-generate reference files for this class |
| 41 | + regenerate_reference = False |
| 42 | + |
| 43 | + def setUp(self): |
| 44 | + os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = '6000' |
| 45 | + os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = '6000' |
| 46 | + super(TestQgsServerWMSGetMapSizeProject, self).setUp() |
| 47 | + self.project = os.path.join(self.testdata_path, "test_project_with_size.qgs") |
| 48 | + self.expected_too_big = self.strip_version_xmlns(b'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="InvalidParameterValue">The requested map size is too large</ServiceException>\n</ServiceExceptionReport>\n') |
| 49 | + |
| 50 | + def test_wms_getmap_invalid_size_project(self): |
| 51 | + # test the 6000 limit from server is overridden by the more conservative 5000 in the project |
| 52 | + r = make_request(self, 5001, 5000) |
| 53 | + self.assertEqual(self.strip_version_xmlns(r), self.expected_too_big) |
| 54 | + |
| 55 | + |
| 56 | +def make_request(instance, height, width): |
| 57 | + qs = "?" + "&".join(["%s=%s" % i for i in list({ |
| 58 | + "MAP": urllib.parse.quote(instance.project), |
| 59 | + "SERVICE": "WMS", |
| 60 | + "VERSION": "1.3.0", |
| 61 | + "REQUEST": "GetMap", |
| 62 | + "LAYERS": "", |
| 63 | + "STYLES": "", |
| 64 | + "FORMAT": "image/png", |
| 65 | + "HEIGHT": str(height), |
| 66 | + "WIDTH": str(width) |
| 67 | + }.items())]) |
| 68 | + r, h = instance._result(instance._execute_request(qs)) |
| 69 | + return instance.strip_version_xmlns(r) |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == '__main__': |
| 73 | + unittest.main() |
0 commit comments