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 feature type without keyword #52

Merged
merged 1 commit into from
Nov 18, 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: 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") == []
)