-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coerce metadata to dict if
select_metadata
is used (#732)
* Change return type of selected metadata to dict * Add note to changelog on select_metadata fix. * Fix lint * Unit test select_metadata --------- Co-authored-by: Dan Allan <[email protected]>
- Loading branch information
1 parent
143dd22
commit 821e06b
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This tests an experimental feature likely to be deprecated. | ||
# https://github.com/bluesky/tiled/issues/217 | ||
import pathlib | ||
|
||
import pytest | ||
|
||
from tiled.catalog import in_memory | ||
from tiled.client import Context, from_context | ||
from tiled.server.app import build_app | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def module_tmp_path(tmp_path_factory: pytest.TempdirFactory) -> pathlib.Path: | ||
return tmp_path_factory.mktemp("temp") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def client(module_tmp_path): | ||
catalog = in_memory(writable_storage=module_tmp_path) | ||
app = build_app(catalog) | ||
with Context.from_app(app) as context: | ||
client = from_context(context) | ||
client.write_array([1], key="x", metadata={"sample": {"color": "red"}}) | ||
client.write_array([2], key="y", metadata={"sample": {"color": "blue"}}) | ||
yield client | ||
|
||
|
||
def test_select_metadata(client): | ||
http_client = client.context.http_client | ||
# /metadata | ||
response = http_client.get("/api/v1/metadata/x?select_metadata=[sample.color]") | ||
result = response.json() | ||
assert result["data"]["attributes"]["metadata"] == {"selected": ["red"]} | ||
# /search | ||
response = http_client.get("/api/v1/search/?select_metadata=[sample.color]") | ||
result = response.json() | ||
for item, color in zip(result["data"], ["red", "blue"]): | ||
assert item["attributes"]["metadata"] == {"selected": [color]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters