Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eodag/api/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from stac_pydantic.collection import Extent, Provider, SpatialExtent, TimeInterval
from stac_pydantic.links import Links

from eodag.api.product.metadata_mapping import NOT_AVAILABLE
from eodag.types.queryables import CommonStacMetadata
from eodag.types.stac_metadata import create_stac_metadata_model
from eodag.utils import STAC_VERSION
Expand Down Expand Up @@ -61,7 +62,7 @@ class Collection(BaseModel):

id: str = Field()
title: Optional[str] = Field(default=None)
description: Optional[str] = Field(default=None)
description: str = Field(default=NOT_AVAILABLE)
extent: Extent = Field(
default=Extent(
spatial=SpatialExtent(bbox=[[-180.0, -90.0, 180.0, 90.0]]), # type: ignore
Expand All @@ -75,7 +76,7 @@ class Collection(BaseModel):
),
)
keywords: Optional[list[str]] = Field(default=None)
license: Optional[str] = Field(default=None)
license: str = Field(default="other")
links: Optional[Links] = Field(default=None)
providers: Optional[list[Provider]] = Field(default=None)

Expand Down
48 changes: 43 additions & 5 deletions tests/integration/test_core_search_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@
mock,
)

STAC_SCHEMAS_DIR = os.path.join(TEST_RESOURCES_PATH, "stac", "schemas")


def _build_stac_schema_map():
"""Build a mapping of remote schema URLs to local file paths from $id fields."""
schema_map = {}
for filename in os.listdir(STAC_SCHEMAS_DIR):
if not filename.endswith(".json"):
continue
filepath = os.path.join(STAC_SCHEMAS_DIR, filename)
with open(filepath) as f:
schema = json.load(f)
schema_id = schema.get("$id")
if schema_id:
schema_map[schema_id.rstrip("#")] = filepath
return schema_map


STAC_SCHEMA_MAP = _build_stac_schema_map()


class TestCoreSearchResults(EODagTestCase):
def setUp(self):
Expand Down Expand Up @@ -124,7 +144,10 @@ def test_core_serialize_search_results_with_filename(self):
path = self.dag.serialize(self.search_result, filename=f.name)
self.assertEqual(path, f.name)
stac = stac_validator.StacValidate(
path, item_collection=True, links=True, assets=True
path,
item_collection=True,
core=True,
schema_map=STAC_SCHEMA_MAP,
)
stac.validate_item_collection()
for msg in stac.message:
Expand All @@ -151,7 +174,11 @@ def test_core_serialize_search_results_with_filename(self):
collection_path = tmpdir_path / f"{self.search_result[0].collection}.json"
self.assertTrue(collection_path.exists())
# validate STAC collection
stac = stac_validator.StacValidate(str(collection_path))
stac = stac_validator.StacValidate(
str(collection_path),
core=True,
schema_map=STAC_SCHEMA_MAP,
)
stac.run()
for msg in stac.message:
self.assertTrue(msg["valid_stac"], stac.message)
Expand Down Expand Up @@ -180,7 +207,10 @@ def test_core_serialize_search_results_unknown_collection(self):
path = self.dag.serialize(self.search_result, filename=f.name)
self.assertEqual(path, f.name)
stac = stac_validator.StacValidate(
path, item_collection=True, links=True, assets=True
path,
item_collection=True,
core=True,
schema_map=STAC_SCHEMA_MAP,
)
stac.validate_item_collection()
for msg in stac.message:
Expand All @@ -192,11 +222,19 @@ def test_core_serialize_search_results_unknown_collection(self):
self.assertTrue(collection1_path.exists())
self.assertTrue(collection2_path.exists())
# validate STAC collections
stac = stac_validator.StacValidate(str(collection1_path))
stac = stac_validator.StacValidate(
str(collection1_path),
core=True,
schema_map=STAC_SCHEMA_MAP,
)
stac.run()
for msg in stac.message:
self.assertTrue(msg["valid_stac"], stac.message)
stac = stac_validator.StacValidate(str(collection2_path))
stac = stac_validator.StacValidate(
str(collection2_path),
core=True,
schema_map=STAC_SCHEMA_MAP,
)
stac.run()
for msg in stac.message:
self.assertTrue(msg["valid_stac"], stac.message)
Expand Down
24 changes: 24 additions & 0 deletions tests/resources/stac/schemas/bands-v1.1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schemas.stacspec.org/v1.1.0/item-spec/json-schema/bands.json",
"title": "Bands Field",
"type": "object",
"properties": {
"bands": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"allOf": [
{
"$ref": "common.json"
}
]
}
}
}
}
34 changes: 34 additions & 0 deletions tests/resources/stac/schemas/basics-v1.1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schemas.stacspec.org/v1.1.0/item-spec/json-schema/basics.json",
"title": "Basic Descriptive Fields",
"type": "object",
"properties": {
"title": {
"title": "Title",
"description": "A human-readable title describing the entity.",
"type": "string"
},
"description": {
"title": "Description",
"description": "Detailed multi-line description to fully explain the entity.",
"type": "string",
"minLength": 1
},
"keywords": {
"title": "Keywords",
"description": "List of keywords describing the entity.",
"type": "array",
"items": {
"type": "string"
}
},
"roles": {
"title": "Roles",
"type": "array",
"items": {
"type": "string"
}
}
}
}
Loading
Loading