Skip to content

Commit 54ef951

Browse files
Sonia-96Yue Sun
andauthored
Fix the bug that resource_id is wrong (#28)
* fix the bug that resource_id is wrong * fix lint issues and the broken test * fix broken tests --------- Co-authored-by: Yue Sun <[email protected]>
1 parent 24e149f commit 54ef951

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

tests/unit_tests/test_geoserver_engine.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,6 @@ def test_create_shapefile_resource(self, mock_catalog, mock_put):
22852285

22862286
mc.get_default_workspace.assert_called_with()
22872287
mc.get_resource.assert_called_with(
2288-
name=self.store_names[0],
22892288
store=self.store_names[0],
22902289
workspace=self.workspace_name[0],
22912290
)
@@ -2321,7 +2320,7 @@ def test_create_shapefile_resource_zipfile(self, mock_catalog, mock_put):
23212320
self.assertIn(self.store_name[0], r["store"])
23222321

23232322
mc.get_resource.assert_called_with(
2324-
name="test1", store=self.store_names[0], workspace=self.workspace_name
2323+
store=self.store_names[0], workspace=self.workspace_name
23252324
)
23262325

23272326
@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):
23642363
self.assertIn(self.store_name[0], r["store"])
23652364

23662365
mc.get_resource.assert_called_with(
2367-
name=self.store_names[0],
23682366
store=self.store_names[0],
23692367
workspace=self.workspace_name,
23702368
)
@@ -2440,7 +2438,6 @@ def test_create_shapefile_resource_overwrite_store_not_exists(
24402438
self.assertIn(self.store_name[0], r["store"])
24412439

24422440
mc.get_resource.assert_called_with(
2443-
name=self.store_names[0],
24442441
store=self.store_names[0],
24452442
workspace=self.workspace_name,
24462443
)

tethys_dataset_services/engines/geoserver_engine.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,6 @@ def create_sql_view_layer(
19631963
template = Template(text)
19641964
xml = template.render(context)
19651965

1966-
19671966
# Decide method, aligned with current GWC REST:
19681967
# PUT => add new layer, POST => modify existing layer
19691968
method = (gwc_method or "AUTO").upper()
@@ -2219,19 +2218,9 @@ def create_shapefile_resource(self, store_id, shapefile_base=None, shapefile_zip
22192218
self._handle_debug(response_dict, debug)
22202219
return response_dict
22212220

2222-
if shapefile_base:
2223-
# This case uses the store name as the Resource ID.
2224-
resource_id = name
2225-
elif shapefile_zip:
2226-
# This case uses the filename as the Resource ID.
2227-
resource_id = os.path.splitext(os.path.basename(shapefile_zip))[0]
2228-
elif shapefile_upload:
2229-
# This case uses the store name as the Resource ID.
2230-
resource_id = name
2231-
22322221
# Set the default style
22332222
if default_style is not None:
2234-
layer_url = self._assemble_url('layers', f'{workspace}:{resource_id}.xml')
2223+
layer_url = self._assemble_url("layers", name)
22352224
layer_headers = {"Content-Type": "application/xml"}
22362225
layer_data = f"""
22372226
<layer>
@@ -2259,7 +2248,7 @@ def create_shapefile_resource(self, store_id, shapefile_base=None, shapefile_zip
22592248

22602249
# Wrap up successfully
22612250
new_resource = self.catalog.get_resource(
2262-
name=resource_id, store=name, workspace=workspace
2251+
store=name, workspace=workspace
22632252
)
22642253
resource_dict = self._transcribe_geoserver_object(new_resource)
22652254

@@ -3040,8 +3029,7 @@ def delete_layer_group(self, layer_group_id):
30403029
if not workspace:
30413030
workspace = self.catalog.get_default_workspace().name
30423031

3043-
url = self._assemble_url("workspaces", workspace, "layergroups",
3044-
f"{group_name}")
3032+
url = self._assemble_url("workspaces", workspace, "layergroups", f"{group_name}")
30453033
response = requests.delete(
30463034
url,
30473035
auth=(self.username, self.password),

0 commit comments

Comments
 (0)