Skip to content

Commit

Permalink
use validate method to validate both item and datacube extension
Browse files Browse the repository at this point in the history
  • Loading branch information
huard committed Nov 16, 2023
1 parent bcf69f2 commit c8669c1
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions tests/test_cmip6_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from STACpopulator.stac_utils import STAC_item_from_metadata
from STACpopulator.implementations.CMIP6_UofT.add_CMIP6 import CMIP6ItemProperties
from STACpopulator.models import GeoJSONPolygon
from pystac import Item
from pystac.validation.stac_validator import JsonSchemaSTACValidator

DIR = Path(__file__).parent

Expand All @@ -23,18 +21,7 @@ def test_datacube_helper():
dc_ext = DatacubeExtension.ext(item, add_if_missing=True)
dc_ext.apply(dimensions=dc.dimensions, variables=dc.variables)

# Get schema for version of datacube extension used
ext_version = item.stac_extensions[0].split("/")[-2]

# Try to find the schema locally, otherwise it will be fetched from the net.
schema_uri = DIR / "schemas" / "datacube" / f"{ext_version}.json"
if not schema_uri.exists():
schema_uri = item.stac_extensions[0]

# Validate
val = JsonSchemaSTACValidator()
val.validate_extension(stac_dict=item.to_dict(),
stac_object_type=Item,
stac_version="1.0",
extension_id=schema_uri)

schemas = item.validate()
assert len(schemas) >= 2
assert "item.json" in schemas[0]
assert "datacube" in schemas[1]

0 comments on commit c8669c1

Please sign in to comment.