From 8824688a51276bd0e52792519bfe13e5bc668ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9cile=20Vuilleumier?= Date: Mon, 18 Nov 2024 10:17:28 +0100 Subject: [PATCH] Support feature type without keyword --- geoservercloud/models/featuretype.py | 10 ++++++---- tests/models/test_featuretype.py | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/geoservercloud/models/featuretype.py b/geoservercloud/models/featuretype.py index 2b761d4..d117d47 100644 --- a/geoservercloud/models/featuretype.py +++ b/geoservercloud/models/featuretype.py @@ -41,7 +41,7 @@ def __init__( namespace_name: str | None = None, title: dict[str, str] | str | None = None, abstract: dict[str, str] | str | None = None, - keywords: list[str] | None = [], + keywords: list[str] | None = None, native_bounding_box: dict[str, Any] | None = None, lat_lon_bounding_box: dict[str, Any] | None = None, attributes: list[dict[str, Any]] | None = None, @@ -130,7 +130,6 @@ def from_get_response_payload(cls, content: dict): title=title, abstract=abstract, srs=feature_type["srs"], - keywords=feature_type["keywords"]["string"], attributes=feature_type["attributes"]["attribute"], metadata_links=metadata_links, enabled=feature_type["enabled"], @@ -142,6 +141,7 @@ def from_get_response_payload(cls, content: dict): advertised=feature_type.get("advertised"), native_bounding_box=feature_type.get("nativeBoundingBox"), lat_lon_bounding_box=feature_type.get("latLonBoundingBox"), + keywords=feature_type.get("keywords", {}).get("string", []), encode_measures=feature_type.get("encodeMeasures"), forced_decimals=feature_type.get("forcedDecimals"), simple_conversion_enabled=feature_type.get("simpleConversionEnabled"), @@ -194,8 +194,10 @@ def asdict(self) -> dict[str, Any]: def post_payload(self) -> dict[str, Any]: content = self.asdict() - content["attributes"] = {"attribute": self.attributes} - content["keywords"] = {"string": self.keywords} + if self.attributes is not None: + content["attributes"] = {"attribute": self.attributes} + if self.keywords is not None: + content["keywords"] = {"string": self.keywords} return {"featureType": content} def put_payload(self) -> dict[str, Any]: diff --git a/tests/models/test_featuretype.py b/tests/models/test_featuretype.py index 100a112..b1ce5f3 100644 --- a/tests/models/test_featuretype.py +++ b/tests/models/test_featuretype.py @@ -252,3 +252,29 @@ def test_featuretype_repr(): expected_repr = json.dumps(feature_type.post_payload(), indent=4) assert repr(feature_type) == expected_repr + + +def test_featuretype_create_no_keyword(): + feature_type = FeatureType( + namespace_name="test_namespace", + workspace_name="test_workspace", + store_name="test_store", + name="test_name", + native_name="test_native_name", + keywords=None, + ) + + assert feature_type.post_payload()["featureType"].get("keywords") is None + + feature_type = FeatureType( + namespace_name="test_namespace", + workspace_name="test_workspace", + store_name="test_store", + name="test_name", + native_name="test_native_name", + keywords=[], + ) + + assert ( + feature_type.post_payload()["featureType"].get("keywords").get("string") == [] + )