From 270a545f26f1706d4ba48a14b2fa6c362d06db8b Mon Sep 17 00:00:00 2001 From: Luca Fabbri Date: Mon, 29 Jul 2024 15:29:24 +0200 Subject: [PATCH] Now expose cads:hidden (#82) --- cads_catalogue_api_service/client.py | 3 ++- schemas/dataset_preview.json | 6 ++++++ tests/test_10_serializers.py | 22 ++++++++++++++++++++++ tests/testing.py | 3 ++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cads_catalogue_api_service/client.py b/cads_catalogue_api_service/client.py index d6064a5..1c652f1 100644 --- a/cads_catalogue_api_service/client.py +++ b/cads_catalogue_api_service/client.py @@ -377,6 +377,7 @@ def collection_serializer( # ***************************************** **({"cads:message": active_message} if active_message else {}), "cads:disabled_reason": db_model.disabled_reason, + **({"cads:hidden": db_model.hidden} if db_model.hidden else {}), } if schema_org: @@ -402,7 +403,7 @@ def collection_serializer( else [] ), # https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#license - # note that this small check, evenif correct, is triggering a lot of subrequests + # note that this small check, even if correct, is triggering a lot of subrequests license=( "various" if not preview and len(db_model.licences) > 1 else "proprietary" ), diff --git a/schemas/dataset_preview.json b/schemas/dataset_preview.json index 398cbe6..9c0c2c7 100644 --- a/schemas/dataset_preview.json +++ b/schemas/dataset_preview.json @@ -47,6 +47,12 @@ "format": "date-time" } } + }, + "cads:hidden": { + "type": "boolean", + "title": "Hidden", + "description": "Whether this dataset is hidden from the public", + "default": false } }, "required": ["published", "updated"] diff --git a/tests/test_10_serializers.py b/tests/test_10_serializers.py index 8c77b46..2ed2f6c 100644 --- a/tests/test_10_serializers.py +++ b/tests/test_10_serializers.py @@ -55,3 +55,25 @@ def test_collection_serializer(monkeypatch) -> None: ) assert stac_record == generate_expected(request.base_url, schema_org=True) + + +def test_hidden(monkeypatch) -> None: + """Test cads:hidden properly shown on STAC.""" + monkeypatch.setattr( + "cads_catalogue_api_service.client.get_active_message", + fake_get_active_message, + ) + request = Request("https://mycatalogue.org/") # note the final slash! + record = get_record("era5-something") + stac_record = cads_catalogue_api_service.client.collection_serializer( + record, session=object(), request=request + ) + + assert "cads:hidden" not in stac_record + + record = get_record("era5-something", hidden=True) + stac_record = cads_catalogue_api_service.client.collection_serializer( + record, session=object(), request=request + ) + + assert stac_record["cads:hidden"] is True diff --git a/tests/testing.py b/tests/testing.py index 3421895..d57647f 100644 --- a/tests/testing.py +++ b/tests/testing.py @@ -26,7 +26,7 @@ def url_for(self, __name: str, **kwargs: str) -> str: return "/collections" -def get_record(id: str) -> cads_catalogue.database.Resource: +def get_record(id: str, hidden=False) -> cads_catalogue.database.Resource: return cads_catalogue.database.Resource( resource_uid=id, title="ERA5", @@ -94,6 +94,7 @@ def get_record(id: str) -> cads_catalogue.database.Resource: qa_flag=True, disabled_reason="Disabled because of a reason", layout="resouces/reanalysis-era5-pressure-levels/layout.json", + hidden=hidden, )