diff --git a/stac_pydantic/extensions.py b/stac_pydantic/extensions.py index 5baf498..1818e8c 100644 --- a/stac_pydantic/extensions.py +++ b/stac_pydantic/extensions.py @@ -11,7 +11,7 @@ @lru_cache(maxsize=128) -def _fetch_schema(url: str) -> dict: +def _fetch_and_cache_schema(url: str) -> dict: """Fetch the remote JSON schema, if not already cached.""" req = requests.get(url) return req.json() @@ -35,7 +35,7 @@ def validate_extensions( try: if stac_dict["stac_extensions"]: for ext in stac_dict["stac_extensions"]: - schema = _fetch_schema(ext) + schema = _fetch_and_cache_schema(ext) jsonschema.validate(instance=stac_dict, schema=schema) except Exception: if reraise_exception: diff --git a/tests/test_models.py b/tests/test_models.py index 0b135e4..6e10a2f 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -6,7 +6,7 @@ from shapely.geometry import shape from stac_pydantic import Collection, Item, ItemProperties -from stac_pydantic.extensions import _fetch_schema, validate_extensions +from stac_pydantic.extensions import _fetch_and_cache_schema, validate_extensions from stac_pydantic.links import Link, Links from stac_pydantic.shared import MimeTypes, StacCommonMetadata @@ -120,16 +120,16 @@ def test_extension_validation_schema_cache() -> None: # Defines 3 extensions, but one is a non-existing URL test_item = request(EO_EXTENSION) - _fetch_schema.cache_clear() + _fetch_and_cache_schema.cache_clear() assert not validate_extensions(test_item) - assert _fetch_schema.cache_info().hits == 0 - assert _fetch_schema.cache_info().misses == 3 + assert _fetch_and_cache_schema.cache_info().hits == 0 + assert _fetch_and_cache_schema.cache_info().misses == 3 assert not validate_extensions(test_item) - assert _fetch_schema.cache_info().hits == 2 + assert _fetch_and_cache_schema.cache_info().hits == 2 # The non-existing URL will have failed, hence retried - assert _fetch_schema.cache_info().misses == 4 + assert _fetch_and_cache_schema.cache_info().misses == 4 @pytest.mark.parametrize(