Skip to content

Commit

Permalink
Add alternative reference json files for getlegendgraphic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 29, 2022
1 parent 3dea6de commit c2f8e7f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 31 deletions.
63 changes: 40 additions & 23 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -62,32 +62,49 @@ def wms_request(self, request, extra=None, project='test_project.qgs', version='
def wms_request_compare(self, request, extra=None, reference_file=None, project='test_project.qgs', version='1.3.0', ignoreExtent=False, normalizeJson=False, raw=False):
response_header, response_body, query_string = self.wms_request(request, extra, project, version)
response = response_header + response_body
reference_path = os.path.join(self.testdata_path, (request.lower() if not reference_file else reference_file) + '.txt')
self.store_reference(reference_path, response)
f = open(reference_path, 'rb')
expected = f.read()

def _n(r):
lines = r.split(b'\n')
b = lines[2:]
h = lines[:2]
try:
return b'\n'.join(h) + json.dumps(json.loads(b'\n'.join(b))).encode('utf8')
except:
return r

response = _n(response)
expected = _n(expected)
if not isinstance(reference_file, (list, tuple)):
reference_files = [reference_file]
else:
reference_files = reference_file

last_exception = None
found_match = False
for reference_file in reference_files:
reference_path = os.path.join(self.testdata_path, (request.lower() if not reference_file else reference_file) + '.txt')
self.store_reference(reference_path, response)
f = open(reference_path, 'rb')
expected = f.read()

def _n(r):
lines = r.split(b'\n')
b = lines[2:]
h = lines[:2]
try:
return b'\n'.join(h) + json.dumps(json.loads(b'\n'.join(b))).encode('utf8')
except:
return r

response = _n(response)
expected = _n(expected)

f.close()
response = re.sub(RE_STRIP_UNCHECKABLE, b'*****', response)
expected = re.sub(RE_STRIP_UNCHECKABLE, b'*****', expected)
if ignoreExtent:
response = re.sub(RE_STRIP_EXTENTS, b'*****', response)
expected = re.sub(RE_STRIP_EXTENTS, b'*****', expected)

msg = "request %s failed.\nQuery: %s\nExpected file: %s\nResponse:\n%s" % (query_string, request, reference_path, response.decode('utf-8'))

f.close()
response = re.sub(RE_STRIP_UNCHECKABLE, b'*****', response)
expected = re.sub(RE_STRIP_UNCHECKABLE, b'*****', expected)
if ignoreExtent:
response = re.sub(RE_STRIP_EXTENTS, b'*****', response)
expected = re.sub(RE_STRIP_EXTENTS, b'*****', expected)
try:
self.assertXMLEqual(response, expected, msg=msg, raw=raw)
found_match = True
except AssertionError as e:
last_exception = e

msg = "request %s failed.\nQuery: %s\nExpected file: %s\nResponse:\n%s" % (query_string, request, reference_path, response.decode('utf-8'))
self.assertXMLEqual(response, expected, msg=msg, raw=raw)
if not found_match:
raise last_exception


class TestQgsServerWMS(TestQgsServerWMSTestBase):
Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/test_qgsserver_wms_getlegendgraphic.py
Expand Up @@ -1007,19 +1007,19 @@ def test_wms_GetLegendGraphic_JSON(self):
self.wms_request_compare("GetLegendGraphic",
"&LAYERS=testlayer%20%C3%A8%C3%A9"
"&FORMAT=application/json",
"wms_getlegendgraphic_json")
["wms_getlegendgraphic_json", "wms_getlegendgraphic_json2"])

def test_wms_GetLegendGraphic_JSON_multiple_layers(self):
self.wms_request_compare("GetLegendGraphic",
"&LAYERS=testlayer%20%C3%A8%C3%A9,testlayer3"
"&FORMAT=application/json",
"wms_getlegendgraphic_json_multiple_layers")
["wms_getlegendgraphic_json_multiple_layers", "wms_getlegendgraphic_json_multiple_layers2"])

def test_wms_GetLegendGraphic_JSON_multiple_symbol(self):
self.wms_request_compare("GetLegendGraphic",
"&LAYERS=cdb_lines"
"&FORMAT=application/json",
"wms_getlegendgraphic_json_multiple_symbol",
["wms_getlegendgraphic_json_multiple_symbol", "wms_getlegendgraphic_json_multiple_symbol2"],
'test_project_wms_grouped_layers.qgs')

def testJsonSymbolMaxMinScale(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/qgis_server/wms_getlegendgraphic_json.txt
Expand Up @@ -4,7 +4,7 @@ Content-Type: application/json
{
"nodes":[
{
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC",
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC",
"title":"A test vector layer",
"type":"layer"
}
Expand Down
13 changes: 13 additions & 0 deletions tests/testdata/qgis_server/wms_getlegendgraphic_json2.txt
@@ -0,0 +1,13 @@
*****
Content-Type: application/json

{
"nodes":[
{
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC",
"title":"A test vector layer",
"type":"layer"
}
],
"title":""
}
Expand Up @@ -4,12 +4,12 @@ Content-Type: application/json
{
"nodes":[
{
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAU0lEQVQ4jWNgGAV0A4z4JJWVlf8j8+/evYtTPQs+Q474qaKI2Wxi+I/LMKyC2AxBGHYbq8uYcLmIVDBEDLp79y6jzabbJBlEUvTDLCHJhlFAfQAA+w0alQ045JsAAAAASUVORK5CYII=",
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAAU0lEQVQ4jWNgGAV0A4z4JJWVlf8j8+/evYtTPQs+Q474qaKI2Wxi+I/LMKyC2AxBGHYbq8uYcLmIVDBEDLp79y6jzabbJBlEUvTDLCHJhlFAfQAA+w0alQ045JsAAAAASUVORK5CYII=",
"title":"testlayer3",
"type":"layer"
},
{
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC",
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC",
"title":"A test vector layer",
"type":"layer"
}
Expand Down
@@ -0,0 +1,18 @@
*****
Content-Type: application/json

{
"nodes":[
{
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAU0lEQVQ4jWNgGAV0A4z4JJWVlf8j8+/evYtTPQs+Q474qaKI2Wxi+I/LMKyC2AxBGHYbq8uYcLmIVDBEDLp79y6jzabbJBlEUvTDLCHJhlFAfQAA+w0alQ045JsAAAAASUVORK5CYII=",
"title":"testlayer3",
"type":"layer"
},
{
"icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC",
"title":"A test vector layer",
"type":"layer"
}
],
"title":""
}
Expand Up @@ -6,11 +6,11 @@ Content-Type: application/json
{
"symbols": [
{
"icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAKUlEQVQ4jWP0c/v/n4ESQIkBfm7//zNRZDsDA8OoAaMGjBoAAYyUZmcAMb0KZdjI3VIAAAAASUVORK5CYII=",
"icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAAKUlEQVQ4jWP0c/v/n4ESQIkBfm7//zNRZDsDA8OoAaMGjBoAAYyUZmcAMb0KZdjI3VIAAAAASUVORK5CYII=",
"title": "Ortsteil"
},
{
"icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAKklEQVQ4jWOcOeX/fwZKACUGzJzy/z8TRbYzMDCMGjBqwKgBEMBIaXYGACyFDMn+2JVEAAAAAElFTkSuQmCC",
"icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAAKklEQVQ4jWOcOeX/fwZKACUGzJzy/z8TRbYzMDCMGjBqwKgBEMBIaXYGACyFDMn+2JVEAAAAAElFTkSuQmCC",
"title": "Stadtteil"
}
],
Expand Down
@@ -0,0 +1,22 @@
*****
Content-Type: application/json

{
"nodes": [
{
"symbols": [
{
"icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAKUlEQVQ4jWP0c/v/n4ESQIkBfm7//zNRZDsDA8OoAaMGjBoAAYyUZmcAMb0KZdjI3VIAAAAASUVORK5CYII=",
"title": "Ortsteil"
},
{
"icon": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAKklEQVQ4jWOcOeX/fwZKACUGzJzy/z8TRbYzMDCMGjBqwKgBEMBIaXYGACyFDMn+2JVEAAAAAElFTkSuQmCC",
"title": "Stadtteil"
}
],
"title": "cdb_lines",
"type": "layer"
}
],
"title": ""
}

0 comments on commit c2f8e7f

Please sign in to comment.