Skip to content

Commit 8d2eccc

Browse files
Add unit tests
1 parent 15fe99c commit 8d2eccc

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/test_unit.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,63 @@ def test_invalid(self):
405405

406406
self.assertRaises(api.ShotgunError, api.shotgun._translate_filters, filters, "all")
407407

408+
def test_related_object(self):
409+
filters = [
410+
[
411+
"project",
412+
"is",
413+
{"foo": "foo", "bar": "bar", "id": 999, "baz": "baz", "type": "Anything"},
414+
],
415+
]
416+
expected = {
417+
"logical_operator": "and",
418+
"conditions": [
419+
{
420+
"path": "project",
421+
"relation": "is",
422+
"values": [
423+
{
424+
"foo": "foo",
425+
"bar": "bar",
426+
"baz": "baz",
427+
"id": 999,
428+
"type": "Anything",
429+
}
430+
],
431+
}
432+
],
433+
}
434+
result = api.shotgun._translate_filters(filters, "all")
435+
self.assertEqual(result, expected)
436+
437+
def test_related_object_entity_optimization(self):
438+
filters = [
439+
[
440+
"project",
441+
"is",
442+
{"foo": "foo", "bar": "bar", "id": 999, "baz": "baz", "type": "Anything"},
443+
],
444+
]
445+
expected = {
446+
"logical_operator": "and",
447+
"conditions": [
448+
{
449+
"path": "project",
450+
"relation": "is",
451+
"values": [
452+
{
453+
"id": 999,
454+
"type": "Anything",
455+
}
456+
],
457+
}
458+
],
459+
}
460+
os.environ["SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION"] = "1"
461+
api.Shotgun("http://server_path", "script_name", "api_key", connect=False)
462+
result = api.shotgun._translate_filters(filters, "all")
463+
self.assertEqual(result, expected)
464+
408465

409466
class TestCerts(unittest.TestCase):
410467
# A dummy bad url provided by Amazon
@@ -506,5 +563,6 @@ def _test_mimetypes_import(self, platform, major, minor, patch_number, result, m
506563
mock.platform = platform
507564
self.assertEqual(_is_mimetypes_broken(), result)
508565

566+
509567
if __name__ == '__main__':
510568
unittest.main()

0 commit comments

Comments
 (0)