Repository navigation
Entity lists: Filter by labels in get_entity_lists #385
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
Draft
BigRoy
wants to merge
1
commit into
develop
Choose a base branch
from
enhancement/entity-lists-label-filter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| """Filtering of 'get_entity_lists' by labels. | ||
|
|
||
| Does not require running AYON server. | ||
| """ | ||
| import json | ||
|
|
||
| import pytest | ||
|
|
||
| from ayon_api.server_api import ServerAPI | ||
|
|
||
| from .graphql_fake_server import FakeServer, parse_query | ||
|
|
||
| PROJECT_NAME = "proj" | ||
| LABELS = ["a", "b", "c", "d"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def server(): | ||
| data = { | ||
| "project": { | ||
| "entityLists": [ | ||
| {"id": f"l{idx}", "label": label} | ||
| for idx, label in enumerate(LABELS) | ||
| ], | ||
| }, | ||
| } | ||
| return FakeServer(data) | ||
|
|
||
|
|
||
| def _create_con(monkeypatch, server, server_version): | ||
| con = ServerAPI("http://localhost:0", create_session=False) | ||
| monkeypatch.setattr(con, "query_graphql", server.query_graphql) | ||
| monkeypatch.setattr( | ||
| con, "get_server_version_tuple", lambda: (*server_version, "", "") | ||
| ) | ||
| return con | ||
|
|
||
|
|
||
| def _entity_lists_args(server): | ||
| """Arguments of 'entityLists' field for each sent query.""" | ||
| output = [] | ||
| for query_str, variables in server.calls: | ||
| root = parse_query(query_str, variables) | ||
| output.append(root.child("project").child("entityLists").args) | ||
| return output | ||
|
|
||
|
|
||
| def test_labels_filter_is_sent_to_server(monkeypatch, server): | ||
| con = _create_con(monkeypatch, server, (1, 8, 3)) | ||
|
|
||
| list(con.get_entity_lists( | ||
| PROJECT_NAME, labels=["b", "c"], fields={"id"} | ||
| )) | ||
|
|
||
| args = _entity_lists_args(server) | ||
| assert len(args) == 1 | ||
| query_filter = json.loads(args[0]["filter"]) | ||
| assert query_filter["conditions"][0]["key"] == "label" | ||
| assert query_filter["conditions"][0]["operator"] == "in" | ||
| assert set(query_filter["conditions"][0]["value"]) == {"b", "c"} | ||
|
|
||
|
|
||
| def test_labels_filter_on_client_for_old_server(monkeypatch, server): | ||
| con = _create_con(monkeypatch, server, (1, 8, 2)) | ||
|
|
||
| entity_lists = list(con.get_entity_lists( | ||
| PROJECT_NAME, labels=["b", "c"], fields={"id"} | ||
| )) | ||
|
|
||
| assert [entity_list["id"] for entity_list in entity_lists] == [ | ||
| "l1", "l2" | ||
| ] | ||
| assert "filter" not in _entity_lists_args(server)[0] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("server_version", [(1, 8, 2), (1, 8, 3)]) | ||
| def test_empty_labels_return_nothing(monkeypatch, server, server_version): | ||
| con = _create_con(monkeypatch, server, server_version) | ||
|
|
||
| assert list(con.get_entity_lists( | ||
| PROJECT_NAME, labels=[], fields={"id"} | ||
| )) == [] | ||
| assert not server.calls | ||
|
|
||
|
|
||
| def test_no_labels_does_not_filter(monkeypatch, server): | ||
| con = _create_con(monkeypatch, server, (1, 8, 3)) | ||
|
|
||
| entity_lists = list(con.get_entity_lists(PROJECT_NAME, fields={"id"})) | ||
|
|
||
| assert len(entity_lists) == len(LABELS) | ||
| assert "filter" not in _entity_lists_args(server)[0] |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it actually'd make sense to also expose
filtersitself 🤔