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

Add roles to common metadata #1444

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386))
- Add convenience method for accessing pystac_client ([#1365](https://github.com/stac-utils/pystac/pull/1365))
- Fix field ordering when saving `Item`s ([#1423](https://github.com/stac-utils/pystac/pull/1423))
- Add roles to common metadata ([#1444](https://github.com/stac-utils/pystac/pull/1444/files))

### Changed

Expand Down
9 changes: 9 additions & 0 deletions pystac/common_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,12 @@ def updated(self) -> datetime | None:
@updated.setter
def updated(self, v: datetime | None) -> None:
self._set_field("updated", utils.map_opt(utils.datetime_to_str, v))

@property
def roles(self) -> list[str] | None:
"""Get or set the semantic roles of the entity."""
return self._get_field("roles", list[str])

@roles.setter
def roles(self, v: list[str] | None) -> None:
self._set_field("roles", v)
1 change: 1 addition & 0 deletions tests/data-files/item/sample-item-asset-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"start_datetime": "2017-05-01T13:22:30.040Z",
"end_datetime": "2017-05-02T13:22:30.040Z",
"license": "CC-BY-4.0",
"roles": ["a_role"],
"providers": [
{
"name": "USGS",
Expand Down
22 changes: 22 additions & 0 deletions tests/test_common_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,25 @@ def test_updated(self) -> None:
self.assertEqual(
analytic.to_dict()["updated"], utils.datetime_to_str(set_value)
)

def test_roles(self) -> None:
item = self.item.clone()
cm = item.common_metadata
analytic = item.assets["analytic"]
analytic_cm = CommonMetadata(analytic)
thumbnail = item.assets["thumbnail"]
thumbnail_cm = CommonMetadata(thumbnail)

item_value = cm.roles
a2_known_value = ["a_role"]

# Get
self.assertNotEqual(thumbnail_cm.roles, item_value)
self.assertEqual(thumbnail_cm.roles, a2_known_value)

# Set
set_value = ["another_role"]
analytic_cm.roles = set_value

self.assertEqual(analytic_cm.roles, set_value)
self.assertEqual(analytic.to_dict()["roles"], set_value)