diff --git a/stactools_sentinel2/stactools/sentinel2/stac.py b/stactools_sentinel2/stactools/sentinel2/stac.py index a99223b8..1b211484 100644 --- a/stactools_sentinel2/stactools/sentinel2/stac.py +++ b/stactools_sentinel2/stactools/sentinel2/stac.py @@ -116,8 +116,9 @@ def create_item( for image_path in product_metadata.image_paths ]) - for asset in image_assets.items(): - item.add_asset(*asset) + for key, asset in image_assets.items(): + assert key not in item.assets + item.add_asset(key, asset) # Thumbnail @@ -205,7 +206,7 @@ def set_asset_properties(asset): roles=['data']) item.ext.eo.set_bands([SENTINEL_BANDS[band_id]], asset) set_asset_properties(asset) - return (asset_href[-7:].replace('_', '-'), asset) + return (band_id, asset) # Handle auxiliary images diff --git a/tests/sentinel2/test_commands.py b/tests/sentinel2/test_commands.py index 396df1d9..45d312a9 100644 --- a/tests/sentinel2/test_commands.py +++ b/tests/sentinel2/test_commands.py @@ -7,6 +7,7 @@ from stactools.core.projection import reproject_geom from stactools.sentinel2.commands import create_sentinel2_command +from stactools.sentinel2.constants import SENTINEL_BANDS from tests.utils import (TestData, CliTestCase) @@ -56,7 +57,15 @@ def check_proj_bbox(item): item.validate() + bands_seen = set() + for asset in item.assets.values(): self.assertTrue(is_absolute_href(asset.href)) + bands = item.ext.eo.get_bands(asset) + if bands is not None: + bands_seen |= set(b.name for b in bands) + + self.assertEqual(bands_seen, + set(SENTINEL_BANDS.keys())) check_proj_bbox(item)