generated from linz/template-python-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor fake collection metadata (#1096)
### Motivation The collection metadata used for testing is duplicated in the code base which makes it difficult to maintain. ### Modifications Use the same collection metadata for all the related tests. ### Verification ran pytest
- Loading branch information
1 parent
181e731
commit eed97de
Showing
4 changed files
with
153 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from datetime import datetime | ||
from decimal import Decimal | ||
from typing import Iterator | ||
|
||
import pytest | ||
|
||
from scripts.stac.imagery.metadata_constants import CollectionMetadata | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def fake_collection_metadata() -> Iterator[CollectionMetadata]: | ||
collection_metadata: CollectionMetadata = { | ||
"category": "rural-aerial-photos", | ||
"region": "hawkes-bay", | ||
"gsd": Decimal("0.3"), | ||
"start_datetime": datetime(2023, 1, 1), | ||
"end_datetime": datetime(2023, 2, 2), | ||
"lifecycle": "completed", | ||
"event_name": None, | ||
"historic_survey_number": None, | ||
"geographic_description": None, | ||
} | ||
yield collection_metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,47 @@ | ||
from collections.abc import Generator | ||
from datetime import datetime | ||
from decimal import Decimal | ||
|
||
import pytest | ||
|
||
from scripts.stac.imagery.collection import ImageryCollection | ||
from scripts.stac.imagery.metadata_constants import CollectionMetadata | ||
from scripts.tests.datetimes_test import any_epoch_datetime | ||
|
||
|
||
# pylint: disable=duplicate-code | ||
@pytest.fixture(name="metadata", autouse=True) | ||
def setup() -> Generator[tuple[CollectionMetadata, CollectionMetadata], None, None]: | ||
metadata_auck: CollectionMetadata = { | ||
"category": "rural-aerial-photos", | ||
"region": "auckland", | ||
"gsd": Decimal("0.3"), | ||
"start_datetime": datetime(2023, 1, 1), | ||
"end_datetime": datetime(2023, 2, 2), | ||
"lifecycle": "completed", | ||
"geographic_description": None, | ||
"event_name": None, | ||
"historic_survey_number": None, | ||
} | ||
metadata_hb: CollectionMetadata = { | ||
"category": "rural-aerial-photos", | ||
"region": "hawkes-bay", | ||
"gsd": Decimal("0.3"), | ||
"start_datetime": datetime(2023, 1, 1), | ||
"end_datetime": datetime(2023, 2, 2), | ||
"lifecycle": "completed", | ||
"geographic_description": None, | ||
"event_name": None, | ||
"historic_survey_number": None, | ||
} | ||
yield (metadata_auck, metadata_hb) | ||
|
||
|
||
def test_generate_description_imagery(metadata: tuple[CollectionMetadata, CollectionMetadata]) -> None: | ||
metadata_auck, _ = metadata | ||
collection = ImageryCollection(metadata_auck, any_epoch_datetime) | ||
description = "Orthophotography within the Auckland region captured in the 2023 flying season." | ||
def test_generate_description_imagery(fake_collection_metadata: CollectionMetadata) -> None: | ||
collection = ImageryCollection(fake_collection_metadata, any_epoch_datetime) | ||
description = "Orthophotography within the Hawke's Bay region captured in the 2023 flying season." | ||
assert collection.stac["description"] == description | ||
|
||
|
||
def test_generate_description_elevation(metadata: tuple[CollectionMetadata, CollectionMetadata]) -> None: | ||
metadata_auck, _ = metadata | ||
metadata_auck["category"] = "dem" | ||
collection = ImageryCollection(metadata_auck, any_epoch_datetime) | ||
description = "Digital Elevation Model within the Auckland region captured in 2023." | ||
def test_generate_description_elevation(fake_collection_metadata: CollectionMetadata) -> None: | ||
fake_collection_metadata["category"] = "dem" | ||
collection = ImageryCollection(fake_collection_metadata, any_epoch_datetime) | ||
description = "Digital Elevation Model within the Hawke's Bay region captured in 2023." | ||
assert collection.stac["description"] == description | ||
|
||
|
||
def test_generate_description_elevation_geographic_description_input( | ||
metadata: tuple[CollectionMetadata, CollectionMetadata] | ||
) -> None: | ||
metadata_auck, _ = metadata | ||
metadata_auck["category"] = "dem" | ||
metadata_auck["geographic_description"] = "Central" | ||
collection = ImageryCollection(metadata_auck, any_epoch_datetime) | ||
description = "Digital Elevation Model within the Auckland region captured in 2023." | ||
def test_generate_description_elevation_geographic_description_input(fake_collection_metadata: CollectionMetadata) -> None: | ||
fake_collection_metadata["category"] = "dem" | ||
fake_collection_metadata["geographic_description"] = "Central" | ||
collection = ImageryCollection(fake_collection_metadata, any_epoch_datetime) | ||
description = "Digital Elevation Model within the Hawke's Bay region captured in 2023." | ||
assert collection.stac["description"] == description | ||
|
||
|
||
def test_generate_description_satellite_imagery(metadata: tuple[CollectionMetadata, CollectionMetadata]) -> None: | ||
metadata_auck, _ = metadata | ||
metadata_auck["category"] = "satellite-imagery" | ||
collection = ImageryCollection(metadata_auck, any_epoch_datetime) | ||
description = "Satellite imagery within the Auckland region captured in 2023." | ||
def test_generate_description_satellite_imagery(fake_collection_metadata: CollectionMetadata) -> None: | ||
fake_collection_metadata["category"] = "satellite-imagery" | ||
collection = ImageryCollection(fake_collection_metadata, any_epoch_datetime) | ||
description = "Satellite imagery within the Hawke's Bay region captured in 2023." | ||
assert collection.stac["description"] == description | ||
|
||
|
||
def test_generate_description_historic_imagery(metadata: tuple[CollectionMetadata, CollectionMetadata]) -> None: | ||
metadata_auck, _ = metadata | ||
metadata_auck["category"] = "scanned-aerial-photos" | ||
metadata_auck["historic_survey_number"] = "SNC8844" | ||
collection = ImageryCollection(metadata_auck, any_epoch_datetime) | ||
description = "Scanned aerial imagery within the Auckland region captured in 2023." | ||
def test_generate_description_historic_imagery(fake_collection_metadata: CollectionMetadata) -> None: | ||
fake_collection_metadata["category"] = "scanned-aerial-photos" | ||
fake_collection_metadata["historic_survey_number"] = "SNC8844" | ||
collection = ImageryCollection(fake_collection_metadata, any_epoch_datetime) | ||
description = "Scanned aerial imagery within the Hawke's Bay region captured in 2023." | ||
assert collection.stac["description"] == description | ||
|
||
|
||
def test_generate_description_event(metadata: tuple[CollectionMetadata, CollectionMetadata]) -> None: | ||
_, metadata_hb = metadata | ||
metadata_hb["event_name"] = "Cyclone Gabrielle" | ||
collection = ImageryCollection(metadata_hb, any_epoch_datetime) | ||
def test_generate_description_event(fake_collection_metadata: CollectionMetadata) -> None: | ||
fake_collection_metadata["event_name"] = "Cyclone Gabrielle" | ||
collection = ImageryCollection(fake_collection_metadata, any_epoch_datetime) | ||
description = "Orthophotography within the Hawke's Bay region captured in the 2023 flying season, \ | ||
published as a record of the Cyclone Gabrielle event." | ||
assert collection.stac["description"] == description |
Oops, something went wrong.