Skip to content

Commit

Permalink
fix: derived_from links should not be duplicated when Item is updated T…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Dec 17, 2024
1 parent 3fca23f commit 446fdb9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scripts/stac/imagery/create_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def create_item(
gdalinfo_result = gdal_info(asset_path)

if derived_from 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"]

for derived in derived_from:
derived_item_content = read(derived)
derived_stac = json.loads(derived_item_content.decode("UTF-8"))
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"
}
}

0 comments on commit 446fdb9

Please sign in to comment.