Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tests for meter based default scales
  • Loading branch information
signedav authored and nyalldawson committed Apr 1, 2023
1 parent 5f6ae24 commit 3574972
Show file tree
Hide file tree
Showing 15 changed files with 2,010 additions and 18 deletions.
135 changes: 117 additions & 18 deletions tests/src/python/test_qgsserver_wms_getlegendgraphic.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsServer WMS GetLegendGraphic.
From build dir, run: ctest -R PyQgsServerWMSGetLegendGraphic -V
Expand All @@ -18,6 +19,7 @@
# Needed on Qt 5 so that the serialization of XML is consistent among all executions
os.environ['QT_HASH_SEED'] = '1'

import re
import json
import urllib.request
import urllib.parse
Expand All @@ -40,6 +42,7 @@
QgsBufferServerRequest,
QgsBufferServerResponse,
QgsServer,
QgsServerRequest,
)

# Strip path and content length because path may vary
Expand All @@ -65,10 +68,10 @@ def test_getLegendGraphics(self):
# 'HEIGHT': '20', # optional
'LAYER': 'testlayer%20èé',
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
h, r = self._execute_request(qs)
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), f"Header: {h}\nResponse:\n{r}")
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), f"Header: {h}\nResponse:\n{r}")
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))

def test_wms_GetLegendGraphic_LayerSpace(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
Expand Down Expand Up @@ -187,7 +190,7 @@ def test_wms_getLegendGraphics_layertitle(self):
'LAYERTITLE': 'TRUE',
'RULELABEL': 'TRUE'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_test", 250, QSize(15, 15))

Expand All @@ -208,7 +211,7 @@ def test_wms_getLegendGraphics_layertitle(self):
'ITEMFONTFAMILY': self.fontFamily,
'ITEMFONTSIZE': '20'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))

self._img_diff_error(r, h, "WMS_GetLegendGraphic_test", 250, QSize(15, 15))
Expand All @@ -225,7 +228,7 @@ def test_wms_getLegendGraphics_layertitle(self):
'LAYERTITLE': 'FALSE',
'RULELABEL': 'FALSE'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_test_layertitle_false", 250, QSize(15, 15))

Expand All @@ -246,7 +249,7 @@ def test_wms_getLegendGraphics_rulelabel(self):
'ITEMFONTFAMILY': self.fontFamily,
'RULELABEL': 'FALSE'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rulelabel_false", 250, QSize(15, 15))

Expand All @@ -266,7 +269,7 @@ def test_wms_getLegendGraphics_rulelabel(self):
'LAYERTITLE': 'FALSE',
'RULELABEL': 'TRUE'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rulelabel_true", 250, QSize(15, 15))

Expand All @@ -286,7 +289,7 @@ def test_wms_getLegendGraphics_rulelabel(self):
'ITEMFONTFAMILY': self.fontFamily,
'LAYERTITLE': 'FALSE'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rulelabel_notset", 250, QSize(15, 15))

Expand All @@ -301,7 +304,7 @@ def test_wms_getLegendGraphics_rulelabel(self):
'LAYERTITLE': 'FALSE',
'RULELABEL': 'AUTO'
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rulelabel_auto", 250, QSize(15, 15))

Expand All @@ -318,7 +321,7 @@ def test_wms_getLegendGraphics_rule(self):
'HEIGHT': '20',
'RULE': 'rule0',
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rule0", 250, QSize(15, 15))

Expand All @@ -333,7 +336,7 @@ def test_wms_getLegendGraphics_rule(self):
'HEIGHT': '20',
'RULE': 'rule1',
}
qs = '?' + '&'.join([f"{k}={v}" for k, v in parms.items()])
qs = '?' + '&'.join(["%s=%s" % (k, v) for k, v in parms.items()])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_rule1", 250, QSize(15, 15))

Expand Down Expand Up @@ -628,8 +631,8 @@ def test_wms_GetLegendGraphic_EmptyLegend(self):
}.items())])

h, r = self._execute_request(qs)
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), f"Header: {h}\nResponse:\n{r}")
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), f"Header: {h}\nResponse:\n{r}")
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))

def test_wms_GetLegendGraphic_wmsRootName(self):
"""Test an unreported issue when a wmsRootName short name is set in the service capabilities"""
Expand All @@ -650,8 +653,8 @@ def test_wms_GetLegendGraphic_wmsRootName(self):
}.items())])

h, r = self._execute_request(qs)
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), f"Header: {h}\nResponse:\n{r}")
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), f"Header: {h}\nResponse:\n{r}")
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))

# Then test with the wmsRootName short name:
qs = "?" + "&".join(["%s=%s" % i for i in list({
Expand All @@ -669,8 +672,8 @@ def test_wms_GetLegendGraphic_wmsRootName(self):
}.items())])

h, r = self._execute_request(qs)
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), f"Header: {h}\nResponse:\n{r}")
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), f"Header: {h}\nResponse:\n{r}")
self.assertEqual(-1, h.find(b'Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEqual(-1, h.find(b'Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))

def test_wms_GetLegendGraphic_ScaleSymbol_Min(self):
# 1:500000000 min
Expand Down Expand Up @@ -818,6 +821,102 @@ def test_wms_GetLegendGraphic_ScaleSymbol_DefaultScale_2056(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ScaleSymbol_DefaultScale_2056", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_MetersAtScaleSymbol_Scaled(self):
# meters at scale symbols on EPSG:4326 calculated with BBOX
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_meters_at_scaledsymbols.qgs',
"SERVICE": "WMS",
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"SRCHEIGHT": "2550",
"SRCWIDTH": "3850",
"BBOX": "44.89945254864102964,8.20044117721021948,44.90400902275693085,8.20936038559772285",
"CRS": "EPSG:4326"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_MetersAtScaleSymbol_Scaled", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_MetersAtScaleSymbol_DefaultScale(self):
# meters at scale symbols on EPSG:4326 calculated with Default Scale set in the projects configuration
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_meters_at_scaledsymbols.qgs',
"SERVICE": "WMS",
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"CRS": "EPSG:4326"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_MetersAtScaleSymbol_DefaultScale", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_MetersAtScaleSymbol_Rule(self):
# meters at scale symbols on EPSG:4326 calculated with Default Scale set in the projects configuration and having a rule
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_meters_at_scaledsymbols.qgs',
"SERVICE": "WMS",
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"CRS": "EPSG:4326",
"WIDTH": "50",
"HEIGHT": "50",
"RULE": "two"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_MetersAtScaleSymbol_Rule", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_MetersAtScaleSymbol_Scaled_2056(self):
# meters at scale symbols on EPSG:2056 calculated with BBOX
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_meters_at_scaledsymbols_2056.qgs',
"SERVICE": "WMS",
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer_2056",
"FORMAT": "image/png",
"SRCHEIGHT": "1100",
"SRCWIDTH": "1700",
"BBOX": "2662610.7,1268841.8,2663010.5,1269000.05",
"CRS": "EPSG:2056"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_MetersAtScaleSymbol_Scaled_2056", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_MetersAtScaleSymbol_DefaultScale_2056(self):
# meters at scale symbols on EPSG:2056 calculated with Default Scale set in the projects configuration
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_meters_at_scaledsymbols_2056.qgs',
"SERVICE": "WMS",
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer_2056",
"FORMAT": "image/png",
"CRS": "EPSG:2056"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_MetersAtScaleSymbol_DefaultScale_2056", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_MetersAtScaleSymbol_Rule_2056(self):
# meters at scale symbols on EPSG:2056 calculated with Default Scale set in the projects configuration and having a rule
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_meters_at_scaledsymbols_2056.qgs',
"SERVICE": "WMS",
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer_2056",
"FORMAT": "image/png",
"CRS": "EPSG:2056",
"WIDTH": "50",
"HEIGHT": "50",
"RULE": "test"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_MetersAtScaleSymbol_Rule_2056", max_size_diff=QSize(15, 15))

def test_wms_GetLegendGraphic_LAYERFONTCOLOR(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3574972

Please sign in to comment.