Skip to content

Commit 1be0027

Browse files
Add roles to common metadata (#1444)
* add roles * update changelog * Update pystac/common_metadata.py --------- Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com>
1 parent ba406cb commit 1be0027

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386))
1414
- Add convenience method for accessing pystac_client ([#1365](https://github.com/stac-utils/pystac/pull/1365))
1515
- Fix field ordering when saving `Item`s ([#1423](https://github.com/stac-utils/pystac/pull/1423))
16+
- Add roles to common metadata ([#1444](https://github.com/stac-utils/pystac/pull/1444/files))
1617

1718
### Changed
1819

pystac/common_metadata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,12 @@ def updated(self) -> datetime | None:
213213
@updated.setter
214214
def updated(self, v: datetime | None) -> None:
215215
self._set_field("updated", utils.map_opt(utils.datetime_to_str, v))
216+
217+
@property
218+
def roles(self) -> list[str] | None:
219+
"""Get or set the semantic roles of the entity."""
220+
return self._get_field("roles", list[str])
221+
222+
@roles.setter
223+
def roles(self, v: list[str] | None) -> None:
224+
self._set_field("roles", v)

tests/data-files/item/sample-item-asset-properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"start_datetime": "2017-05-01T13:22:30.040Z",
7575
"end_datetime": "2017-05-02T13:22:30.040Z",
7676
"license": "CC-BY-4.0",
77+
"roles": ["a_role"],
7778
"providers": [
7879
{
7980
"name": "USGS",

tests/test_common_metadata.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,25 @@ def test_updated(self) -> None:
538538
self.assertEqual(
539539
analytic.to_dict()["updated"], utils.datetime_to_str(set_value)
540540
)
541+
542+
def test_roles(self) -> None:
543+
item = self.item.clone()
544+
cm = item.common_metadata
545+
analytic = item.assets["analytic"]
546+
analytic_cm = CommonMetadata(analytic)
547+
thumbnail = item.assets["thumbnail"]
548+
thumbnail_cm = CommonMetadata(thumbnail)
549+
550+
item_value = cm.roles
551+
a2_known_value = ["a_role"]
552+
553+
# Get
554+
self.assertNotEqual(thumbnail_cm.roles, item_value)
555+
self.assertEqual(thumbnail_cm.roles, a2_known_value)
556+
557+
# Set
558+
set_value = ["another_role"]
559+
analytic_cm.roles = set_value
560+
561+
self.assertEqual(analytic_cm.roles, set_value)
562+
self.assertEqual(analytic.to_dict()["roles"], set_value)

0 commit comments

Comments
 (0)