diff --git a/pygeoapi/templates/stac/item.html b/pygeoapi/templates/stac/item.html index cfee31a2c1..6857cc5349 100644 --- a/pygeoapi/templates/stac/item.html +++ b/pygeoapi/templates/stac/item.html @@ -99,7 +99,7 @@

{% trans %}Assets{% endtrans %}

} )); - var bbox = gen_safe_bbox({{ data['extent']['spatial']['bbox'][0] }}); + var bbox = gen_safe_bbox({{ data['bbox'] }}); var bbox_layer = L.polygon([ [bbox[1], bbox[0]], diff --git a/tests/api/test_stac.py b/tests/api/test_stac.py index 1da63919b3..a43e989862 100644 --- a/tests/api/test_stac.py +++ b/tests/api/test_stac.py @@ -31,7 +31,7 @@ import pytest -from pygeoapi.api.stac import search, landing_page +from pygeoapi.api.stac import get_stac_path, landing_page, search from pygeoapi.formats import FORMAT_TYPES, F_JSON from pygeoapi.util import yaml_load @@ -66,6 +66,38 @@ def test_landing_page(config, api_): assert response['description'] == 'pygeoapi provides an API to geospatial data' # noqa +def test_get_stac_item_html(config, api_, monkeypatch): + item = { + 'id': 'test-item', + 'type': 'Feature', + 'bbox': [-10, -5, 10, 5], + 'geometry': None, + 'properties': {}, + 'links': [], + 'assets': { + 'default': { + 'href': 'test-item.tif', + 'created': '2026-09-18T00:00:00Z', + 'file:size': 1024 + } + } + } + + class ItemProvider: + def get_data_path(self, base_url, path, relative_path): + return item + + monkeypatch.setattr('pygeoapi.api.stac.load_plugin', + lambda *args: ItemProvider()) + + request = mock_api_request({'f': 'html'}) + _, code, response = get_stac_path(api_, request, + 'test-data/test-item.tif') + + assert code == 200 + assert 'var bbox = gen_safe_bbox([-10, -5, 10, 5]);' in response + + @pytest.mark.parametrize('params,matched,returned', [ ({}, 10, 10), ({'bbox': '-142,52,-140,55'}, 6, 6),