def test_register_extension(): class TestExtension(BaseModel): foo: str bar: int Extensions.register("test", TestExtension, alias="test_extension") assert Extensions.get("test") == Extensions.get( "test-extension") == TestExtension
def validate_extensions(cls, values): if "stac_extensions" in values: for ext in values["stac_extensions"]: if ext in ("collection-assets", "item-assets", "version"): ext_model = Extensions.get(ext) ext_model(**values) return values
def _extension_model_factory( stac_extensions: Tuple[str], base_class: Type[Item], skip_remote_refs: bool = False) -> Tuple[Type[BaseModel], FieldInfo]: """ Create a stac item properties model for a set of stac extensions """ fields = decompose_model(base_class.__fields__["properties"].type_) for ext in stac_extensions: if skip_remote_refs and ext.startswith("http"): continue if ext == "checksum": continue fields.update(decompose_model(Extensions.get(ext))) return ( create_model("CustomItemProperties", __base__=ItemProperties, **fields), FieldInfo(...), )
def test_get_missing_extension(): with pytest.raises(AttributeError): Extensions.get("not-an-extension")
from stac_pydantic.shared import DATETIME_RFC339 from stac_pydantic.version import STAC_VERSION from .conftest import dict_match, request class LandsatExtension(BaseModel): path: int = Field(..., alias="landsat:path") row: int = Field(..., alias="landsat:row") class Config: allow_population_by_fieldname = True landsat_alias = "https://example.com/stac/landsat-extension/1.0/schema.json" Extensions.register("landsat", LandsatExtension, alias=landsat_alias) COLLECTION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/collection-spec/examples/landsat-collection.json" ITEM_COLLECTION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v0.9.0/item-spec/examples/itemcollection-sample-full.json" SINGLE_FILE_STAC = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/single-file-stac/examples/example-search.json" # ASSET_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/asset/examples/example-landsat8.json" # COLLECTION_ASSET_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/collection-assets/examples/example-esm.json" DATACUBE_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/datacube/examples/example-item.json" EO_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/eo/examples/example-landsat8.json" ITEM_ASSET_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/item-assets/examples/example-landsat8.json" LABEL_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/label/examples/spacenet-roads/roads_item.json" POINTCLOUD_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/pointcloud/examples/example-autzen.json" PROJ_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/projection/examples/example-landsat8.json" SAR_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/sar/examples/sentinel1.json" SAT_EXTENSION = f"https://raw.githubusercontent.com/radiantearth/stac-spec/v{STAC_VERSION}/extensions/sat/examples/example-landsat8.json"