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

fix: handle existing derived_from links when Item is updated TDE-1356 #1220

Merged
merged 2 commits into from
Dec 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
4 changes: 4 additions & 0 deletions scripts/stac/imagery/create_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def create_item(
if not gdalinfo_result:
gdalinfo_result = gdal_info(asset_path)

if item.stac.get("links") is not None:
# Remove existing derived_from links in case of resupply
item.stac["links"] = [link for link in item.stac["links"] if link["rel"] != "derived_from"]

if derived_from is not None:
for derived in derived_from:
derived_item_content = read(derived)
Expand Down
20 changes: 20 additions & 0 deletions scripts/stac/imagery/tests/create_stac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,27 @@ def test_create_item_when_resupplying(subtests: SubTests, tmp_path: Path) -> Non
item_name = "empty"
existing_item = tmp_path / f"{item_name}.json"
tiff_path = f"./scripts/tests/data/{item_name}.tiff"
derived_from_path = "./scripts/tests/data/fake_item.json"
created_datetime = "created datetime"
updated_datetime = "updated datetime"
links = [
{
"href": derived_from_path,
"rel": "derived_from",
"type": "application/geo+json",
"file:checksum": "1220f33d983b9c84d3d0c44f37f4a1b842295a960abcdd3889b898f42988f9e93604",
},
{
"href": "path/to/an/old/derived_from",
"rel": "derived_from",
"type": "application/geo+json",
"file:checksum": "123",
},
]
existing_item_content = {
"type": "Feature",
"id": item_name,
"links": links,
"assets": {
"visual": {
"href": tiff_path,
Expand All @@ -77,6 +93,7 @@ def test_create_item_when_resupplying(subtests: SubTests, tmp_path: Path) -> Non
"any GDAL version",
current_datetime,
fake_gdal_info,
derived_from=[derived_from_path],
odr_url=tmp_path.as_posix(),
)

Expand All @@ -92,6 +109,9 @@ def test_create_item_when_resupplying(subtests: SubTests, tmp_path: Path) -> Non
with subtests.test(msg="assets.visual.updated"):
assert item.stac["assets"]["visual"]["updated"] == updated_datetime

with subtests.test(msg="links"):
assert len(item.stac["links"]) == 3


def test_create_item_when_resupplying_with_changed_file(subtests: SubTests, tmp_path: Path) -> None:
item_name = "empty"
Expand Down
8 changes: 8 additions & 0 deletions scripts/tests/data/fake_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "Feature",
"id": "Fake Item",
"properties": {
"start_datetime": "2018-11-30T11:00:00Z",
"end_datetime": "2020-01-31T11:00:00Z"
}
}
Loading