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

Deal with non-i18ned attribute values #58

Merged
merged 2 commits into from
Nov 20, 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
10 changes: 10 additions & 0 deletions geoservercloud/geoservercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ def create_feature_type(
)
return self.rest_service.create_feature_type(feature_type=feature_type)

def delete_feature_type(
self, workspace_name: str, datastore_name: str, layer_name: str
) -> tuple[str, int]:
"""
Delete a feature type and associated layer
"""
return self.rest_service.delete_feature_type(
workspace_name, datastore_name, layer_name
)

def create_layer_group(
self,
group: str,
Expand Down
12 changes: 9 additions & 3 deletions geoservercloud/models/featuretype.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def from_get_response_payload(cls, content: dict):
feature_type = content["featureType"]
workspace_name = feature_type["store"]["name"].split(":")[0]
store_name = feature_type["store"]["name"].split(":")[1]
title = feature_type.get("title", feature_type.get("internationalTitle"))
title = feature_type.get("internationalTitle", feature_type.get("title"))
abstract = feature_type.get(
"abstract", feature_type.get("internationalAbstract")
"internationalAbstract", feature_type.get("abstract")
)
if feature_type.get("metadataLinks"):
metadata_links_payload = feature_type["metadataLinks"]["metadataLink"]
Expand Down Expand Up @@ -201,7 +201,13 @@ def post_payload(self) -> dict[str, Any]:
return {"featureType": content}

def put_payload(self) -> dict[str, Any]:
return self.post_payload()
content = self.post_payload()
# Force a null value on non-i18ned attributes, otherwise GeoServer sets it to the first i18n value
if content["featureType"].get("internationalTitle"):
content["featureType"]["title"] = None
if content["featureType"].get("internationalAbstract"):
content["featureType"]["abstract"] = None
return content

def __repr__(self):
return json.dumps(self.post_payload(), indent=4)
9 changes: 9 additions & 0 deletions geoservercloud/services/restservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ def create_feature_type(self, feature_type: FeatureType) -> tuple[str, int]:
)
return response.content.decode(), response.status_code

def delete_feature_type(
self, workspace_name: str, datastore_name: str, layer_name: str
) -> tuple[str, int]:
response: Response = self.rest_client.delete(
self.rest_endpoints.featuretype(workspace_name, datastore_name, layer_name),
params={"recurse": "true"},
)
return response.content.decode(), response.status_code

def create_layer_group(
self,
group: str,
Expand Down
30 changes: 28 additions & 2 deletions tests/test_feature_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ def feature_type_post_payload(
return {"featureType": content}


@pytest.fixture(scope="module")
def feature_type_put_payload(
feature_type_post_payload: dict[str, dict[str, Any]]
) -> dict[str, dict[str, Any]]:
content = feature_type_post_payload.copy()
content["featureType"]["title"] = None
content["featureType"]["abstract"] = None
return content


def test_get_feature_types(
geoserver: GeoServerCloud, feature_types_get_response_payload: dict[str, Any]
) -> None:
Expand Down Expand Up @@ -218,7 +228,7 @@ def test_create_feature_type(


def test_update_feature_type(
geoserver: GeoServerCloud, feature_type_post_payload: dict[str, dict[str, Any]]
geoserver: GeoServerCloud, feature_type_put_payload: dict[str, dict[str, Any]]
) -> None:
with responses.RequestsMock() as rsps:
rsps.get(
Expand All @@ -227,7 +237,7 @@ def test_update_feature_type(
)
rsps.put(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/datastores/{STORE}/featuretypes/{LAYER}.json",
match=[responses.matchers.json_params_matcher(feature_type_post_payload)],
match=[responses.matchers.json_params_matcher(feature_type_put_payload)],
status=200,
body=b"",
)
Expand All @@ -242,3 +252,19 @@ def test_update_feature_type(

assert content == ""
assert code == 200


def test_delete_feature_type(geoserver: GeoServerCloud) -> None:
with responses.RequestsMock() as rsps:
rsps.delete(
f"{geoserver.url}/rest/workspaces/{WORKSPACE}/datastores/{STORE}/featuretypes/{LAYER}.json",
status=200,
body=b"",
match=[responses.matchers.query_param_matcher({"recurse": "true"})],
)
content, code = geoserver.delete_feature_type(
workspace_name=WORKSPACE, datastore_name=STORE, layer_name=LAYER
)

assert content == ""
assert code == 200