Skip to content

Commit

Permalink
Now expose cads:hidden (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
keul authored Jul 29, 2024
1 parent 8d2d26f commit 270a545
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cads_catalogue_api_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
),
Expand Down
6 changes: 6 additions & 0 deletions schemas/dataset_preview.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
22 changes: 22 additions & 0 deletions tests/test_10_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
)


Expand Down

0 comments on commit 270a545

Please sign in to comment.