Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support i18n titles in cascaded layers #16

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions geoservercloud/geoservercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,17 @@ def create_wmts_layer(
native_layer: str,
published_layer: str | None = None,
epsg: int = 4326,
) -> Response | None:
international_title: dict[str, str] | None = None,
international_abstract: dict[str, str] | None = None,
) -> Response:
"""
Publish a remote WMTS layer if it does not already exist.
Publish a remote WMTS layer (first delete it if it already exists)
"""
if not published_layer:
published_layer = native_layer
if self.resource_exists(
f"/rest/workspaces/{workspace}/wmtsstores/{wmts_store}/layers/{published_layer}.json"
):
return None
resource_path = f"/rest/workspaces/{workspace}/wmtsstores/{wmts_store}/layers/{published_layer}.json"
if self.resource_exists(resource_path):
self.delete_request(resource_path, params={"recurse": "true"})
wmts_store_path = f"/rest/workspaces/{workspace}/wmtsstores/{wmts_store}.json"
capabilities_url = (
self.get_request(wmts_store_path)
Expand All @@ -337,7 +338,12 @@ def create_wmts_layer(

path = f"/rest/workspaces/{workspace}/wmtsstores/{wmts_store}/layers.json"
payload = Templates.wmts_layer(
published_layer, native_layer, wgs84_bbox=wgs84_bbox, epsg=epsg
published_layer,
native_layer,
wgs84_bbox=wgs84_bbox,
epsg=epsg,
international_title=international_title,
international_abstract=international_abstract,
)

return self.post_request(path, json=payload)
Expand Down
6 changes: 6 additions & 0 deletions geoservercloud/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def wmts_layer(
native_name: str,
epsg: int = 4326,
wgs84_bbox: tuple[float, float, float, float] | None = None,
international_title: dict[str, str] | None = None,
international_abstract: dict[str, str] | None = None,
) -> dict[str, dict[str, Any]]:
template = {
"wmtsLayer": {
Expand Down Expand Up @@ -293,6 +295,10 @@ def wmts_layer(
"miny": wgs84_bbox[1],
"maxy": wgs84_bbox[3],
}
if international_title:
template["wmtsLayer"]["internationalTitle"] = international_title
if international_abstract:
template["wmtsLayer"]["internationalAbstract"] = international_abstract
return template

@staticmethod
Expand Down
64 changes: 62 additions & 2 deletions tests/test_cascaded_wmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,78 @@ def test_create_wmts_layer(
assert response.status_code == 201


def test_create_wmts_layer_already_exists(geoserver: GeoServerCloud) -> None:
def test_create_wmts_layer_already_exists(
geoserver: GeoServerCloud, wmts_layer_payload: dict[str, dict[str, Any]]
) -> None:
with responses.RequestsMock() as rsps:
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}/layers/{LAYER}.json",
status=200,
)
rsps.delete(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}/layers/{LAYER}.json",
status=200,
match=[responses.matchers.query_param_matcher({"recurse": "true"})],
)
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
status=200,
json={"wmtsStore": {"capabilitiesURL": CAPABILITIES_URL}},
)
rsps.get(
CAPABILITIES_URL,
status=200,
body=CAPABILITIES,
headers={"Content-Type": "application/xml"},
)
rsps.post(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}/layers.json",
match=[responses.matchers.json_params_matcher(wmts_layer_payload)],
status=201,
)
response = geoserver.create_wmts_layer(
workspace=WORKSPACE,
wmts_store=STORE,
native_layer=NATIVE_LAYER,
published_layer=LAYER,
)

assert response.status_code == 201


def test_create_wmts_layer_international_title(
geoserver: GeoServerCloud, wmts_layer_payload: dict[str, dict[str, Any]]
) -> None:
wmts_layer_payload["wmtsLayer"]["internationalTitle"] = {"en": "Title"}
wmts_layer_payload["wmtsLayer"]["internationalAbstract"] = {"en": "Abstract"}
with responses.RequestsMock() as rsps:
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}/layers/{LAYER}.json",
status=404,
)
rsps.get(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}.json",
status=200,
json={"wmtsStore": {"capabilitiesURL": CAPABILITIES_URL}},
)
rsps.get(
CAPABILITIES_URL,
status=200,
body=CAPABILITIES,
headers={"Content-Type": "application/xml"},
)
rsps.post(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/wmtsstores/{STORE}/layers.json",
match=[responses.matchers.json_params_matcher(wmts_layer_payload)],
status=201,
)
response = geoserver.create_wmts_layer(
workspace=WORKSPACE,
wmts_store=STORE,
native_layer=NATIVE_LAYER,
published_layer=LAYER,
international_title={"en": "Title"},
international_abstract={"en": "Abstract"},
)

assert response is None
assert response.status_code == 201
Loading