@@ -290,6 +290,8 @@ def test_py_version(self, mock_sys):
290290
291291
292292class TestFilters (unittest .TestCase ):
293+ maxDiff = None
294+
293295 def test_empty (self ):
294296 expected = {
295297 "logical_operator" : "and" ,
@@ -463,6 +465,28 @@ def test_related_object_entity_optimization_is(self):
463465 result = api .shotgun ._translate_filters (filters , "all" )
464466 self .assertEqual (result , expected )
465467
468+ # Now test a non-related object. The expected result should not be optimized.
469+ filters = [
470+ [
471+ "something" ,
472+ "is" ,
473+ {"foo" : "foo" , "bar" : "bar" },
474+ ],
475+ ]
476+ expected = {
477+ "logical_operator" : "and" ,
478+ "conditions" : [
479+ {
480+ "path" : "something" ,
481+ "relation" : "is" ,
482+ "values" : [{'bar' : 'bar' , 'foo' : 'foo' }],
483+ }
484+ ],
485+ }
486+ api .Shotgun ("http://server_path" , "script_name" , "api_key" , connect = False )
487+ result = api .shotgun ._translate_filters (filters , "all" )
488+ self .assertEqual (result , expected )
489+
466490 @mock .patch .dict (os .environ , {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION" : "1" })
467491 def test_related_object_entity_optimization_in (self ):
468492 filters = [
@@ -471,7 +495,8 @@ def test_related_object_entity_optimization_in(self):
471495 "in" ,
472496 [
473497 {"foo1" : "foo1" , "bar1" : "bar1" , "id" : 999 , "baz1" : "baz1" , "type" : "Anything" },
474- {"foo2" : "foo2" , "bar2" : "bar2" , "id" : 998 , "baz2" : "baz2" , "type" : "Anything" }
498+ {"foo2" : "foo2" , "bar2" : "bar2" , "id" : 998 , "baz2" : "baz2" , "type" : "Anything" },
499+ {"foo3" : "foo3" , "bar3" : "bar3" },
475500 ],
476501 ],
477502 ]
@@ -489,6 +514,10 @@ def test_related_object_entity_optimization_in(self):
489514 {
490515 "id" : 998 ,
491516 "type" : "Anything" ,
517+ },
518+ {
519+ "foo3" : "foo3" ,
520+ "bar3" : "bar3" ,
492521 }
493522 ],
494523 }
@@ -498,6 +527,124 @@ def test_related_object_entity_optimization_in(self):
498527 result = api .shotgun ._translate_filters (filters , "all" )
499528 self .assertEqual (result , expected )
500529
530+ def test_related_object_update_entity (self ):
531+ entity_type = "Anything"
532+ entity_id = 999
533+ multi_entity_update_modes = {"link" : "set" , "name" : "set" }
534+ data = {
535+ "name" : "test" ,
536+ "link" : {
537+ "name" : "test" ,
538+ "url" : "http://test.com" ,
539+ },
540+ }
541+ expected = {
542+ "id" : 999 ,
543+ "type" : "Anything" ,
544+ "fields" : [
545+ {
546+ "field_name" : "name" ,
547+ "value" : "test" ,
548+ "multi_entity_update_mode" : "set" ,
549+ },
550+ {
551+ "field_name" : "link" ,
552+ "value" : {
553+ "name" : "test" ,
554+ "url" : "http://test.com" ,
555+ },
556+ "multi_entity_update_mode" : "set" ,
557+ },
558+ ],
559+ }
560+ sg = api .Shotgun ("http://server_path" , "script_name" , "api_key" , connect = False )
561+ result = sg ._translate_update_params (entity_type , entity_id , data , multi_entity_update_modes )
562+ self .assertEqual (result , expected )
563+
564+ @mock .patch .dict (os .environ , {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION" : "1" })
565+ def test_related_object_update_optimization_entity (self ):
566+ entity_type = "Anything"
567+ entity_id = 999
568+ multi_entity_update_modes = {"project" : "set" , "link" : "set" , "name" : "set" }
569+ data = {
570+ "name" : "test" ,
571+ "link" : {
572+ "name" : "test" ,
573+ "url" : "http://test.com" ,
574+ },
575+ "project" : {
576+ "foo1" : "foo1" ,
577+ "bar1" : "bar1" ,
578+ "id" : 888 ,
579+ "baz1" : "baz1" ,
580+ "type" : "Project" ,
581+ },
582+ }
583+ expected = {
584+ "id" : 999 ,
585+ "type" : "Anything" ,
586+ "fields" : [
587+ {
588+ "field_name" : "name" ,
589+ "value" : "test" ,
590+ "multi_entity_update_mode" : "set" ,
591+ },
592+ {
593+ "field_name" : "link" ,
594+ "value" : {
595+ "name" : "test" ,
596+ "url" : "http://test.com" ,
597+ },
598+ "multi_entity_update_mode" : "set" ,
599+ },
600+ {
601+ "field_name" : "project" ,
602+ "multi_entity_update_mode" : "set" ,
603+ "value" : {
604+ # Entity is optimized with type/id fields.
605+ "id" : 888 ,
606+ "type" : "Project" ,
607+ },
608+ },
609+ ],
610+ }
611+ sg = api .Shotgun ("http://server_path" , "script_name" , "api_key" , connect = False )
612+ result = sg ._translate_update_params (entity_type , entity_id , data , multi_entity_update_modes )
613+ self .assertEqual (result , expected )
614+
615+ @mock .patch .dict (os .environ , {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION" : "1" })
616+ def test_related_object_update_optimization_entity_multi (self ):
617+ entity_type = "Asset"
618+ entity_id = 6626
619+ data = {
620+ "sg_status_list" : "ip" ,
621+ "project" : {"id" : 70 , "type" : "Project" , "name" : "disposable name 70" },
622+ "sg_vvv" : [
623+ {"id" : 6441 , "type" : "Asset" , "name" : "disposable name 6441" },
624+ {"id" : 6440 , "type" : "Asset" },
625+ ],
626+ "sg_class" : {"id" : 1 , "type" : "CustomEntity53" , "name" : "disposable name 1" },
627+ }
628+ expected = {
629+ "type" : "Asset" ,
630+ "id" : 6626 ,
631+ "fields" : [
632+ {"field_name" : "sg_status_list" , "value" : "ip" },
633+ {"field_name" : "project" , "value" : {"type" : "Project" , "id" : 70 }},
634+ {
635+ "field_name" : "sg_vvv" ,
636+ "value" : [
637+ {"id" : 6441 , "type" : "Asset" },
638+ {"id" : 6440 , "type" : "Asset" },
639+ ],
640+ },
641+ {"field_name" : "sg_class" , "value" : {"type" : "CustomEntity53" , "id" : 1 }},
642+ ],
643+ }
644+ sg = api .Shotgun ("http://server_path" , "script_name" , "api_key" , connect = False )
645+ result = sg ._translate_update_params (entity_type , entity_id , data , None )
646+ self .assertEqual (result , expected )
647+
501648
502649class TestCerts (unittest .TestCase ):
503650 # A dummy bad url provided by Amazon
0 commit comments