Skip to content

Commit

Permalink
feat: add item processing software topo-imagery version
Browse files Browse the repository at this point in the history
  • Loading branch information
l0b0 committed Sep 19, 2024
1 parent a86e4f7 commit cd888fc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion scripts/stac/imagery/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def __init__(self, id_: str, file: str, gdal_version: str, now: Callable[[], dat
"created": now_string,
"updated": now_string,
"processing:datetime": now_string,
"processing:software": {"gdal": gdal_version},
"processing:software": {
"gdal": gdal_version,
"linz/topo-imagery": f"https://github.com/linz/topo-imagery/commit/{environ['GIT_HASH']}",
},
"processing:version": environ["GIT_VERSION"],
},
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/stac/imagery/tests/collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_add_item(metadata: CollectionMetadata, subtests: SubTests) -> None:
item_file_path = "./scripts/tests/data/empty.tiff"
modified_datetime = datetime(2001, 2, 3, hour=4, minute=5, second=6, tzinfo=timezone.utc)
os.utime(item_file_path, times=(any_epoch_datetime().timestamp(), modified_datetime.timestamp()))
with patch.dict(os.environ, {"GIT_VERSION": "any Git version"}):
with patch.dict(os.environ, {"GIT_HASH": "any Git hash", "GIT_VERSION": "any Git version"}):
item = ImageryItem("BR34_5000_0304", item_file_path, "any GDAL version", now_function)
geometry = {
"type": "Polygon",
Expand Down
4 changes: 2 additions & 2 deletions scripts/stac/imagery/tests/create_stac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_create_item_with_derived_from(tmp_path: Path) -> None:
GdalInfo, {"wgs84Extent": {"type": "Polygon", "coordinates": [[[0, 1], [1, 1], [1, 0], [0, 0]]]}}
)

with patch.dict(environ, {"GIT_VERSION": "any Git version"}):
with patch.dict(environ, {"GIT_HASH": "any Git hash", "GIT_VERSION": "any Git version"}):
item = create_item(
"./scripts/tests/data/empty.tiff",
"",
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_create_item_with_derived_from_datetimes(tmp_path: Path) -> None:
GdalInfo, {"wgs84Extent": {"type": "Polygon", "coordinates": [[[0, 1], [1, 1], [1, 0], [0, 0]]]}}
)

with patch.dict(environ, {"GIT_VERSION": "any Git version"}):
with patch.dict(environ, {"GIT_HASH": "any Git hash", "GIT_VERSION": "any Git version"}):
item = create_item(
"./scripts/tests/data/empty.tiff",
"",
Expand Down
10 changes: 7 additions & 3 deletions scripts/stac/imagery/tests/item_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def test_imagery_stac_item(mocker: MockerFixture, subtests: SubTests) -> None:
def fake_now() -> datetime:
return datetime(1979, 1, 1, tzinfo=timezone.utc)

git_hash = "any Git hash"
git_version = "any Git version string"
gdal_version_string = "any GDAL version string"
with patch.dict(environ, {"GIT_VERSION": git_version}):
with patch.dict(environ, {"GIT_HASH": git_hash, "GIT_VERSION": git_version}):
item = ImageryItem(id_, path, gdal_version_string, fake_now)
item.update_spatial(geometry, bbox)
item.update_datetime(start_datetime, end_datetime)
Expand Down Expand Up @@ -61,7 +62,10 @@ def fake_now() -> datetime:
assert item.stac["properties"]["processing:version"] == git_version

with subtests.test():
assert item.stac["properties"]["processing:software"] == {"gdal": gdal_version_string}
assert item.stac["properties"]["processing:software"] == {
"gdal": gdal_version_string,
"linz/topo-imagery": f"https://github.com/linz/topo-imagery/commit/{git_hash}",
}

with subtests.test():
assert item.stac["stac_extensions"] == [StacExtensions.file.value, StacExtensions.processing.value]
Expand Down Expand Up @@ -104,7 +108,7 @@ def test_imagery_add_collection(mocker: MockerFixture, subtests: SubTests) -> No
path = "./scripts/tests/data/empty.tiff"
id_ = get_file_name_from_path(path)
mocker.patch("scripts.files.fs.read", return_value=b"")
with patch.dict(environ, {"GIT_VERSION": "any Git version"}):
with patch.dict(environ, {"GIT_HASH": "any Git hash", "GIT_VERSION": "any Git version"}):
item = ImageryItem(id_, path, "any GDAL version", any_epoch_datetime)

item.add_collection(collection.stac["id"])
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/collection_from_items_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@pytest.fixture(name="item", autouse=True)
def setup() -> Generator[ImageryItem, None, None]:
# Create mocked STAC Item
with patch.dict(environ, {"GIT_VERSION": "any Git version"}):
with patch.dict(environ, {"GIT_HASH": "any Git hash", "GIT_VERSION": "any Git version"}):
item = ImageryItem("123", "./scripts/tests/data/empty.tiff", "any GDAL version", utc_now)
geometry = {
"type": "Polygon",
Expand Down

0 comments on commit cd888fc

Please sign in to comment.