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

SG-37544 Include the "in" and "not_in" operators for payload optimization #362

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4482,16 +4482,11 @@ def _translate_filters_simple(sg_filter):
if (
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
and condition["path"] != "id"
and condition["relation"] in ["is", "is_not"]
and condition["relation"] in ["is", "is_not", "in", "not_in"]
and isinstance(values[0], dict)
):
try:
values = [
{
"type": values[0]["type"],
"id": values[0]["id"],
}
]
values = [{"type": v["type"], "id": v["id"]} for v in values]
except KeyError:
pass

Expand Down
37 changes: 36 additions & 1 deletion tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def test_related_object(self):
result = api.shotgun._translate_filters(filters, "all")
self.assertEqual(result, expected)

def test_related_object_entity_optimization(self):
def test_related_object_entity_optimization_is(self):
filters = [
[
"project",
Expand Down Expand Up @@ -462,6 +462,41 @@ def test_related_object_entity_optimization(self):
result = api.shotgun._translate_filters(filters, "all")
self.assertEqual(result, expected)

def test_related_object_entity_optimization_in(self):
filters = [
[
"project",
"in",
[
{"foo1": "foo1", "bar1": "bar1", "id": 999, "baz1": "baz1", "type": "Anything"},
{"foo2": "foo2", "bar2": "bar2", "id": 998, "baz2": "baz2", "type": "Anything"}
],
],
]
expected = {
"logical_operator": "and",
"conditions": [
{
"path": "project",
"relation": "in",
"values": [
{
"id": 999,
"type": "Anything",
},
{
"id": 998,
"type": "Anything",
}
],
}
],
}
os.environ["SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION"] = "1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this kind of test, in order to leave in the same state, I prefer to use a context:

from unittest import mock
with mock.patch.dict("os.environ", {
  "SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1",
}):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found a way using a decorator for the test case.

api.Shotgun("http://server_path", "script_name", "api_key", connect=False)
result = api.shotgun._translate_filters(filters, "all")
self.assertEqual(result, expected)


class TestCerts(unittest.TestCase):
# A dummy bad url provided by Amazon
Expand Down
Loading