diff --git a/tests/src/python/test_qgsserver_wms.py b/tests/src/python/test_qgsserver_wms.py index 58817f55db6..00f73352a4f 100644 --- a/tests/src/python/test_qgsserver_wms.py +++ b/tests/src/python/test_qgsserver_wms.py @@ -62,32 +62,49 @@ class TestQgsServerWMSTestBase(QgsServerTestBase): 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] + 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')) + try: - return b'\n'.join(h) + json.dumps(json.loads(b'\n'.join(b))).encode('utf8') - except: - return r + self.assertXMLEqual(response, expected, msg=msg, raw=raw) + found_match = True + except AssertionError as e: + last_exception = e - 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')) - self.assertXMLEqual(response, expected, msg=msg, raw=raw) + if not found_match: + raise last_exception class TestQgsServerWMS(TestQgsServerWMSTestBase): diff --git a/tests/src/python/test_qgsserver_wms_getlegendgraphic.py b/tests/src/python/test_qgsserver_wms_getlegendgraphic.py index 5c52336f58c..94860f7aff2 100644 --- a/tests/src/python/test_qgsserver_wms_getlegendgraphic.py +++ b/tests/src/python/test_qgsserver_wms_getlegendgraphic.py @@ -1007,19 +1007,19 @@ class TestQgsServerWMSGetLegendGraphic(TestQgsServerWMSTestBase): 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): diff --git a/tests/testdata/qgis_server/wms_getlegendgraphic_json.txt b/tests/testdata/qgis_server/wms_getlegendgraphic_json.txt index c8d09be9101..1d563fdf296 100644 --- a/tests/testdata/qgis_server/wms_getlegendgraphic_json.txt +++ b/tests/testdata/qgis_server/wms_getlegendgraphic_json.txt @@ -4,7 +4,7 @@ Content-Type: application/json { "nodes":[ { - "icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC", + "icon":"iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAAP0lEQVQ4jWNgGAV0A4wE5P8Tqx6fQf/TljijCMyK2YtTDy6DMAwhZBgTHheRBIaOQYzQsCAakBr9xOgZBbQGAKb+C8EdAkkoAAAAAElFTkSuQmCC", "title":"A test vector layer", "type":"layer" } diff --git a/tests/testdata/qgis_server/wms_getlegendgraphic_json2.txt b/tests/testdata/qgis_server/wms_getlegendgraphic_json2.txt new file mode 100644 index 00000000000..c8d09be9101 --- /dev/null +++ b/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":"" +} diff --git a/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers.txt b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers.txt index 490d9d577f7..80e86233509 100644 --- a/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers.txt +++ b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers.txt @@ -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" } diff --git a/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers2.txt b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers2.txt new file mode 100644 index 00000000000..490d9d577f7 --- /dev/null +++ b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_layers2.txt @@ -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":"" +} diff --git a/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol.txt b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol.txt index e37263f1dce..1768e1a697c 100644 --- a/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol.txt +++ b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol.txt @@ -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" } ], diff --git a/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol2.txt b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol2.txt new file mode 100644 index 00000000000..e37263f1dce --- /dev/null +++ b/tests/testdata/qgis_server/wms_getlegendgraphic_json_multiple_symbol2.txt @@ -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": "" +}