From 03334a6e18e0647e40cec3d2f2a5a854b6cec6cc Mon Sep 17 00:00:00 2001 From: Yue Sun Date: Wed, 10 Sep 2025 18:02:45 -0600 Subject: [PATCH 1/3] fix the bug that resource_id is wrong --- .../engines/geoserver_engine.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tethys_dataset_services/engines/geoserver_engine.py b/tethys_dataset_services/engines/geoserver_engine.py index 9cc3a83..f6e6918 100644 --- a/tethys_dataset_services/engines/geoserver_engine.py +++ b/tethys_dataset_services/engines/geoserver_engine.py @@ -2219,19 +2219,9 @@ def create_shapefile_resource(self, store_id, shapefile_base=None, shapefile_zip self._handle_debug(response_dict, debug) return response_dict - if shapefile_base: - # This case uses the store name as the Resource ID. - resource_id = name - elif shapefile_zip: - # This case uses the filename as the Resource ID. - resource_id = os.path.splitext(os.path.basename(shapefile_zip))[0] - elif shapefile_upload: - # This case uses the store name as the Resource ID. - resource_id = name - # Set the default style if default_style is not None: - layer_url = self._assemble_url('layers', f'{workspace}:{resource_id}.xml') + layer_url = self._assemble_url("layers", name) layer_headers = {"Content-Type": "application/xml"} layer_data = f""" @@ -2259,7 +2249,7 @@ def create_shapefile_resource(self, store_id, shapefile_base=None, shapefile_zip # Wrap up successfully new_resource = self.catalog.get_resource( - name=resource_id, store=name, workspace=workspace + name=name, store=name, workspace=workspace ) resource_dict = self._transcribe_geoserver_object(new_resource) From f21ebce055ef63c226ffda602a94b9f4510a8b5f Mon Sep 17 00:00:00 2001 From: Yue Sun Date: Thu, 11 Sep 2025 10:38:17 -0600 Subject: [PATCH 2/3] fix lint issues and the broken test --- tests/unit_tests/test_geoserver_engine.py | 2 +- tethys_dataset_services/engines/geoserver_engine.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_geoserver_engine.py b/tests/unit_tests/test_geoserver_engine.py index 329968f..432fca1 100644 --- a/tests/unit_tests/test_geoserver_engine.py +++ b/tests/unit_tests/test_geoserver_engine.py @@ -2321,7 +2321,7 @@ def test_create_shapefile_resource_zipfile(self, mock_catalog, mock_put): self.assertIn(self.store_name[0], r["store"]) mc.get_resource.assert_called_with( - name="test1", store=self.store_names[0], workspace=self.workspace_name + name=self.store_names[0], store=self.store_names[0], workspace=self.workspace_name ) @mock.patch("tethys_dataset_services.engines.geoserver_engine.requests.put") diff --git a/tethys_dataset_services/engines/geoserver_engine.py b/tethys_dataset_services/engines/geoserver_engine.py index f6e6918..e7a0c94 100644 --- a/tethys_dataset_services/engines/geoserver_engine.py +++ b/tethys_dataset_services/engines/geoserver_engine.py @@ -1963,7 +1963,6 @@ def create_sql_view_layer( template = Template(text) xml = template.render(context) - # Decide method, aligned with current GWC REST: # PUT => add new layer, POST => modify existing layer method = (gwc_method or "AUTO").upper() @@ -3030,8 +3029,7 @@ def delete_layer_group(self, layer_group_id): if not workspace: workspace = self.catalog.get_default_workspace().name - url = self._assemble_url("workspaces", workspace, "layergroups", - f"{group_name}") + url = self._assemble_url("workspaces", workspace, "layergroups", f"{group_name}") response = requests.delete( url, auth=(self.username, self.password), From 7edec6920e02d95ccdcab5a2c71b8db6594be1ff Mon Sep 17 00:00:00 2001 From: Yue Sun Date: Thu, 11 Sep 2025 14:52:07 -0600 Subject: [PATCH 3/3] fix broken tests --- tests/unit_tests/test_geoserver_engine.py | 5 +---- tethys_dataset_services/engines/geoserver_engine.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_geoserver_engine.py b/tests/unit_tests/test_geoserver_engine.py index 432fca1..13a0923 100644 --- a/tests/unit_tests/test_geoserver_engine.py +++ b/tests/unit_tests/test_geoserver_engine.py @@ -2285,7 +2285,6 @@ def test_create_shapefile_resource(self, mock_catalog, mock_put): mc.get_default_workspace.assert_called_with() mc.get_resource.assert_called_with( - name=self.store_names[0], store=self.store_names[0], workspace=self.workspace_name[0], ) @@ -2321,7 +2320,7 @@ def test_create_shapefile_resource_zipfile(self, mock_catalog, mock_put): self.assertIn(self.store_name[0], r["store"]) mc.get_resource.assert_called_with( - name=self.store_names[0], store=self.store_names[0], workspace=self.workspace_name + store=self.store_names[0], workspace=self.workspace_name ) @mock.patch("tethys_dataset_services.engines.geoserver_engine.requests.put") @@ -2364,7 +2363,6 @@ def test_create_shapefile_resource_upload(self, mock_catalog, mock_put): self.assertIn(self.store_name[0], r["store"]) mc.get_resource.assert_called_with( - name=self.store_names[0], store=self.store_names[0], workspace=self.workspace_name, ) @@ -2440,7 +2438,6 @@ def test_create_shapefile_resource_overwrite_store_not_exists( self.assertIn(self.store_name[0], r["store"]) mc.get_resource.assert_called_with( - name=self.store_names[0], store=self.store_names[0], workspace=self.workspace_name, ) diff --git a/tethys_dataset_services/engines/geoserver_engine.py b/tethys_dataset_services/engines/geoserver_engine.py index e7a0c94..395cb83 100644 --- a/tethys_dataset_services/engines/geoserver_engine.py +++ b/tethys_dataset_services/engines/geoserver_engine.py @@ -2248,7 +2248,7 @@ def create_shapefile_resource(self, store_id, shapefile_base=None, shapefile_zip # Wrap up successfully new_resource = self.catalog.get_resource( - name=name, store=name, workspace=workspace + store=name, workspace=workspace ) resource_dict = self._transcribe_geoserver_object(new_resource)