Skip to content

Commit

Permalink
Cascade delete WMTS layer
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Nov 4, 2024
1 parent dd184cb commit dcdbaab
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions geoservercloud/geoservercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ def publish_gwc_layer(
) -> tuple[str, int]:
return self.rest_service.publish_gwc_layer(workspace_name, layer, epsg)

def delete_gwc_layer(self, workspace_name: str, layer: str) -> tuple[str, int]:
return self.rest_service.delete_gwc_layer(workspace_name, layer)

def get_styles(
self, workspace_name: str | None = None
) -> tuple[list[str] | str, int]:
Expand Down
8 changes: 8 additions & 0 deletions geoservercloud/services/restservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def create_wmts_layer(
resource_path,
params={"recurse": "true"},
)
# Also delete the corresponding GWC layer (delete is not cascaded when using REST API)
self.delete_gwc_layer(workspace_name, published_layer)
capabilities_url: str = (
self.rest_client.get(
self.rest_endpoints.wmtsstore(workspace_name, wmts_store)
Expand Down Expand Up @@ -227,6 +229,12 @@ def publish_gwc_layer(
)
return response.content.decode(), response.status_code

def delete_gwc_layer(self, workspace_name: str, layer: str) -> tuple[str, int]:
response: Response = self.rest_client.delete(
self.gwc_endpoints.layer(workspace_name, layer)
)
return response.content.decode(), response.status_code

def create_gridset(self, epsg: int) -> tuple[str, int]:
"""
Create a gridset for GeoWebCache for a given projection
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cascaded_wmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def test_create_wmts_layer_already_exists(
status=200,
match=[responses.matchers.query_param_matcher({"recurse": "true"})],
)
rsps.delete(
url=f"{geoserver.url}/gwc/rest/layers/{WORKSPACE}:{LAYER}.json",
status=200,
)
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
status=200,
Expand Down
26 changes: 26 additions & 0 deletions tests/test_gwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ def test_publish_gwc_layer_already_exists(geoserver: GeoServerCloud) -> None:
assert code == 200


def test_delete_gwc_layer(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.delete(
url=f"{geoserver.url}/gwc/rest/layers/{WORKSPACE}:{LAYER}.json",
status=200,
body=b"test_workspace:test_layer deleted",
)

content, code = geoserver.delete_gwc_layer(WORKSPACE, LAYER)
assert content == "test_workspace:test_layer deleted"
assert code == 200


def test_delete_gwc_layer_not_found(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.delete(
url=f"{geoserver.url}/gwc/rest/layers/{WORKSPACE}:{LAYER}.json",
status=404,
body=b"Unknown layer: test_workspace:test_layer",
)

content, code = geoserver.delete_gwc_layer(WORKSPACE, LAYER)
assert content == "Unknown layer: test_workspace:test_layer"
assert code == 404


def test_create_gridset(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.get(
Expand Down

0 comments on commit dcdbaab

Please sign in to comment.