From ff0ca508c53e37324dcc679f2c5781bf3ee42ce2 Mon Sep 17 00:00:00 2001 From: rldhont Date: Fri, 3 Feb 2023 12:34:59 +0100 Subject: [PATCH] Server: Do not display Empty group in Capabilities and project settings The `test_wms_getprojectsettings` in `test_qgsserver_accesscontrol_wms.py` was marked as `Expectedfailure`, after checking duplicated test methods. This test checks that an empty group because fo acces control could not be in GetCapabilities document with settings activated. The same test did not exist for simple getCapabilities. This commit fix it Funded by 3Liz https://3liz.com --- src/server/services/wms/qgswmsgetcapabilities.cpp | 6 ++++++ tests/src/python/test_qgsserver_accesscontrol_wms.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/services/wms/qgswmsgetcapabilities.cpp b/src/server/services/wms/qgswmsgetcapabilities.cpp index f6b9ca268e65..6437de375170 100644 --- a/src/server/services/wms/qgswmsgetcapabilities.cpp +++ b/src/server/services/wms/qgswmsgetcapabilities.cpp @@ -1017,6 +1017,12 @@ namespace QgsWms } handleLayersFromTreeGroup( doc, layerElem, serverIface, project, request, treeGroupChild, wmsLayerInfos, projectSettings ); + + // Check if child layer elements have been added + if ( layerElem.elementsByTagName( QStringLiteral( "Layer" ) ).length() == 0 ) + { + continue; + } } else { diff --git a/tests/src/python/test_qgsserver_accesscontrol_wms.py b/tests/src/python/test_qgsserver_accesscontrol_wms.py index 09f8800863cc..cc76a1cebac2 100644 --- a/tests/src/python/test_qgsserver_accesscontrol_wms.py +++ b/tests/src/python/test_qgsserver_accesscontrol_wms.py @@ -44,6 +44,9 @@ def test_wms_getcapabilities(self): self.assertTrue( str(response).find("Hello") != -1, f"No Hello layer in GetCapabilities\n{response}") + self.assertTrue( + str(response).find("Country_grp") != -1, + f"Unexpected Country_grp layer in GetCapabilities\n{response}") self.assertTrue( str(response).find("Country") != -1, f"No Country layer in GetCapabilities\n{response}") @@ -52,12 +55,13 @@ def test_wms_getcapabilities(self): self.assertTrue( str(response).find("Hello") != -1, f"No Hello layer in GetCapabilities\n{response}") + self.assertFalse( + str(response).find("Country_grp") != -1, + f"Unexpected Country_grp layer in GetCapabilities\n{response}") self.assertFalse( str(response).find("Country") != -1, f"Unexpected Country layer in GetCapabilities\n{response}") - # This test hasn't run yet - @unittest.expectedFailure def test_wms_getprojectsettings(self): query_string = "&".join(["%s=%s" % i for i in list({ "MAP": urllib.parse.quote(self.projectPath), @@ -78,7 +82,7 @@ def test_wms_getprojectsettings(self): f"No Country_grp layer in GetProjectSettings\n{response}") self.assertTrue( str(response).find( - "Country_Diagrams,Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point") != -1, + "Country_Diagrams,Country_Labels,Country,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello_Filter,Hello_OnOff,Hello,db_point") != -1, f"LayerDrawingOrder in GetProjectSettings\n{response}") response, headers = self._get_restricted(query_string) @@ -93,7 +97,7 @@ def test_wms_getprojectsettings(self): f"Unexpected Country_grp layer in GetProjectSettings\n{response}") self.assertTrue( str(response).find( - "Country_Diagrams,Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello,db_point") != -1, + "Country_Diagrams,Country_Labels,dem,Hello_Filter_SubsetString,Hello_Project_SubsetString,Hello_SubsetString,Hello_Filter,Hello,db_point") != -1, f"Wrong LayerDrawingOrder in GetProjectSettings\n{response}") def test_wms_getcontext(self):