Skip to content

Commit

Permalink
allow to write queryables
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-maschler committed May 31, 2024
1 parent 8d0cd0d commit 6e1202b
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pystac_client/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ def _get_queryables_href(self) -> str:
link = self.get_single_link(QUERYABLES_REL)
href = self._get_href(QUERYABLES_REL, link, QUERYABLES_ENDPOINT)
return href

def write_queryables_to(self, queryables: Dict[str, Any], url: str) -> None:
"""Write a queryables to a given endpoint"""
if self._stac_io is None:
raise APIError("API access is not properly configured")
self._stac_io.save_json(url, queryables)

def set_queryables(self, queryables: Dict[str, Any]) -> None:
"""Write a queryables to the default endpoint"""
url = self._get_queryables_href()
self.write_queryables_to(queryables, url)
236 changes: 236 additions & 0 deletions tests/cassettes/test_client/test_set_queryables.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path
import warnings
from datetime import datetime
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, Dict
from urllib.parse import parse_qs, urlsplit
Expand Down Expand Up @@ -752,3 +753,23 @@ def test_fallback_strategy() -> None:

assert (item_root := item.get_single_link("root"))
assert item_root.href == root_href


@pytest.mark.vcr
def test_set_queryables(tmp_path: Path) -> None:
"""Make sure we can write queryables."""

client = Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1/",
)

queryables = client.get_queryables()

# Transactions are not supported in the default StacApiIO
with pytest.raises(APIError):
client.set_queryables(queryables)

# write content to a temp file
tmp_file = tmp_path / "queryables.json"
client.write_queryables_to(queryables, str(tmp_file))
assert json.loads(tmp_file.read_text()) == queryables

0 comments on commit 6e1202b

Please sign in to comment.