Skip to content
Permalink
Browse files

Test for server add min/max scale to symbol json export

  • Loading branch information
elpaso committed Oct 28, 2020
1 parent c1240de commit dabcf7f19148e3c1bb2fe46b06a0f0ce93306e1a
Showing with 44 additions and 1 deletion.
  1. +44 −1 tests/src/python/test_qgsserver_wms_getlegendgraphic.py
@@ -20,6 +20,7 @@
os.environ['QT_HASH_SEED'] = '1'

import re
import json
import urllib.request
import urllib.parse
import urllib.error
@@ -30,7 +31,19 @@
import osgeo.gdal # NOQA

from test_qgsserver_wms import TestQgsServerWMSTestBase
from qgis.core import QgsProject
from qgis.core import (
QgsProject,
QgsMarkerSymbol,
QgsRuleBasedRenderer,
QgsVectorLayer,
)

from qgis.server import (
QgsBufferServerRequest,
QgsBufferServerResponse,
QgsServer,
QgsServerRequest,
)

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = br'MAP=[^"]+|Content-Length: \d+'
@@ -1002,6 +1015,36 @@ def test_wms_GetLegendGraphic_JSON_multiple_layers(self):
"&FORMAT=application/json",
"wms_getlegendgraphic_json_multiple_layers")

def testJsonSymbolMaxMinScale(self):
"""Test min/max scale in symbol json export"""

project = QgsProject()
layer = QgsVectorLayer("Point?field=fldtxt:string",
"layer1", "memory")

symbol = QgsMarkerSymbol.createSimple(
{'name': 'square', 'color': 'red'})

scale_min = 10000
scale_max = 1000
rule = QgsRuleBasedRenderer.Rule(symbol, scale_min, scale_max, '')
rootrule = QgsRuleBasedRenderer.Rule(None)
rootrule.appendChild(rule)
layer.setRenderer(QgsRuleBasedRenderer(rootrule))

project.addMapLayers([layer])

server = QgsServer()
request = QgsBufferServerRequest("/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic" +
"&LAYERS=layer1" +
"&FORMAT=application/json")
response = QgsBufferServerResponse()
server.handleRequest(request, response, project)
j = json.loads(bytes(response.body()))
node = j['nodes'][0]
self.assertEqual(node['scaleMaxDenom'], 1000)
self.assertEqual(node['scaleMinDenom'], 10000)


if __name__ == '__main__':
unittest.main()

0 comments on commit dabcf7f

Please sign in to comment.
You can’t perform that action at this time.