Skip to content

Commit a1dd6c7

Browse files
committed
Implement #370 for Timestamps Extension
1 parent 48fdff7 commit a1dd6c7

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pystac/extensions/timestamps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ def unpublished(self, v: Optional[Datetime]) -> None:
116116
def get_schema_uri(cls) -> str:
117117
return SCHEMA_URI
118118

119-
@staticmethod
120-
def ext(obj: T) -> "TimestampsExtension[T]":
119+
@classmethod
120+
def ext(cls, obj: T) -> "TimestampsExtension[T]":
121121
if isinstance(obj, pystac.Item):
122+
cls.validate_has_extension(obj)
122123
return cast(TimestampsExtension[T], ItemTimestampsExtension(obj))
123124
elif isinstance(obj, pystac.Asset):
125+
cls.validate_has_extension(obj)
124126
return cast(TimestampsExtension[T], AssetTimestampsExtension(obj))
125127
else:
126128
raise pystac.ExtensionTypeError(

tests/extensions/test_timestamps.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,21 @@ def test_unpublished(self) -> None:
185185

186186
# Validate
187187
timestamps_item.validate()
188+
189+
def test_extension_not_implemented(self) -> None:
190+
# Should raise exception if Item does not include extension URI
191+
item = pystac.Item.from_file(self.example_uri)
192+
item.stac_extensions.remove(TimestampsExtension.get_schema_uri())
193+
194+
with self.assertRaises(pystac.ExtensionNotImplemented):
195+
_ = TimestampsExtension.ext(item)
196+
197+
# Should raise exception if owning Item does not include extension URI
198+
asset = item.assets["blue"]
199+
200+
with self.assertRaises(pystac.ExtensionNotImplemented):
201+
_ = TimestampsExtension.ext(asset)
202+
203+
# Should succeed if Asset has no owner
204+
ownerless_asset = pystac.Asset.from_dict(asset.to_dict())
205+
_ = TimestampsExtension.ext(ownerless_asset)

0 commit comments

Comments
 (0)