Skip to content

Commit

Permalink
Support feature type without keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
vuilleumierc committed Nov 18, 2024
1 parent 3df1416 commit 2731266
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 6 additions & 4 deletions geoservercloud/models/featuretype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"],
Expand All @@ -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"),
Expand Down Expand Up @@ -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]:
Expand Down
26 changes: 26 additions & 0 deletions tests/models/test_featuretype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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") == []
)

0 comments on commit 2731266

Please sign in to comment.