Skip to content

Commit

Permalink
feat: impl migration
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Oct 13, 2023
1 parent 0399580 commit 8bf6cdc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pystac/extensions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,16 @@ def __init__(self, item_asset: AssetDefinition):

class VersionExtensionHooks(ExtensionHooks):
schema_uri = SCHEMA_URI
prev_extension_ids = {"version"}
stac_object_types = {STACObjectType.COLLECTION, STACObjectType.ITEM}
prev_extension_ids = {
"version",
"https://stac-extensions.github.io/version/v1.0.0/schema.json",
"https://stac-extensions.github.io/version/v1.1.0/schema.json",
}
stac_object_types = {
STACObjectType.COLLECTION,
STACObjectType.ITEM,
STACObjectType.CATALOG,
}

def get_object_links(self, so: STACObject) -> list[str] | None:
if isinstance(so, Collection) or isinstance(so, Item):
Expand Down
13 changes: 13 additions & 0 deletions tests/extensions/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,16 @@ def test_assets(item: Item) -> None:
assert "version" in asset.extra_fields

item.validate()


@pytest.mark.parametrize("version", ["v1.0.0", "v1.1.0"])
def test_migrate(version: str, item: Item) -> None:
item_dict = item.to_dict(include_self_link=False, transform_hrefs=False)
item_dict["stac_extensions"] = [
f"https://stac-extensions.github.io/version/{version}/schema.json"
]
item = Item.from_dict(item_dict, migrate=True)
assert (
"https://stac-extensions.github.io/version/v1.2.0/schema.json"
in item.stac_extensions
)

0 comments on commit 8bf6cdc

Please sign in to comment.