Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoint for querying multiple metadata #311

Merged
merged 16 commits into from
Aug 20, 2023
3 changes: 3 additions & 0 deletions terracotta/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class TerracottaSettings(NamedTuple):
#: Use a process pool for band retrieval in parallel
USE_MULTIPROCESSING: bool = True

#: Maximum number of metadata keys per POST /metadata request
MAX_POST_METADATA_KEYS: int = 100


AVAILABLE_SETTINGS: Tuple[str, ...] = TerracottaSettings._fields

Expand Down
2 changes: 1 addition & 1 deletion terracotta/handlers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def multiple_metadata(

out = []
with driver.connect():
for dataset in datasets:
for dataset in datasets[:settings.MAX_POST_METADATA_KEYS]:
dionhaefner marked this conversation as resolved.
Show resolved Hide resolved
metadata = filter_metadata(driver.get_metadata(dataset), columns)
metadata["keys"] = OrderedDict(zip(key_names, dataset))
out.append(metadata)
Expand Down
25 changes: 25 additions & 0 deletions tests/server/test_flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ def test_get_metadata_nonexisting(client, use_testdb):
assert rv.status_code == 404


def test_post_metadata(client, use_testdb):
rv = client.post(
"/metadata",
json={
"keys": [["val11", "x", "val12"], ["val21", "x", "val22"]]
},
)

assert rv.status_code == 200
assert len(json.loads(rv.data)) == 2


def test_post_metadata_specific_columns(client, use_testdb):
rv = client.post(
'/metadata?columns=["bounds", "range"]',
json={
"keys": [["val11", "x", "val12"], ["val21", "x", "val22"]]
},
)

assert rv.status_code == 200
assert len(json.loads(rv.data)) == 2
assert set(json.loads(rv.data)[0].keys()) == {"bounds", "range", "keys"}


def test_get_datasets(client, use_testdb):
rv = client.get("/datasets")
assert rv.status_code == 200
Expand Down
Loading