@@ -2678,6 +2678,72 @@ def test_multiple_latest_filters(self):
26782678 self .sg .find ,
26792679 "Version" , filters , fields = fields , additional_filter_presets = additional_filters )
26802680
2681+ def test_modify_visibility (self ):
2682+ """
2683+ Ensure the visibility of a field can be edited via the API.
2684+ """
2685+ # If the version of Shotgun is too old, do not run this test.
2686+ # TODO: Update this with the real version number once the feature is released.
2687+ if self .sg_version < (8 , 5 , 0 ):
2688+ warnings .warn ("Test bypassed because SG server used does not support this feature." , FutureWarning )
2689+ return
2690+
2691+ field_display_name = "Project Visibility Test"
2692+ field_name = "sg_{0}" .format (field_display_name .lower ().replace (" " , "_" ))
2693+
2694+ schema = self .sg .schema_field_read ("Asset" )
2695+ # Ensure the custom field exists.
2696+ if field_name not in schema :
2697+ self .sg .schema_field_create ("Asset" , "text" , "Project Visibility Test" )
2698+
2699+ # Grab any two projects that we can use for toggling the visible property with.
2700+ projects = self .sg .find ("Project" , [], order = [{"field_name" : "id" , "direction" : "asc" }])
2701+ project_1 = projects [0 ]
2702+ project_2 = projects [1 ]
2703+
2704+ # First, reset the field visibility in a known state, i.e. visible for both projects,
2705+ # in case the last test run failed midway through.
2706+ self .sg .schema_field_update ("Asset" , field_name , {"visible" : True }, project_1 )
2707+ self .assertEqual (
2708+ {"value" : True , "editable" : True },
2709+ self .sg .schema_field_read ("Asset" , field_name , project_1 )[field_name ]["visible" ]
2710+ )
2711+ self .sg .schema_field_update ("Asset" , field_name , {"visible" : True }, project_2 )
2712+ self .assertEqual (
2713+ {"value" : True , "editable" : True },
2714+ self .sg .schema_field_read ("Asset" , field_name , project_2 )[field_name ]["visible" ]
2715+ )
2716+
2717+ # Built-in fields should remain not editable.
2718+ self .assertFalse (self .sg .schema_field_read ("Asset" , "code" )["code" ]["visible" ]["editable" ])
2719+
2720+ # Custom fields should be editable
2721+ self .assertEqual (
2722+ {"value" : True , "editable" : True },
2723+ self .sg .schema_field_read ("Asset" , field_name )[field_name ]["visible" ]
2724+ )
2725+
2726+ # Hide the field on project 1
2727+ self .sg .schema_field_update ("Asset" , field_name , {"visible" : False }, project_1 )
2728+ # It should not be visible anymore.
2729+ self .assertEqual (
2730+ {"value" : False , "editable" : True },
2731+ self .sg .schema_field_read ("Asset" , field_name , project_1 )[field_name ]["visible" ]
2732+ )
2733+
2734+ # The field should be visible on the second project.
2735+ self .assertEqual (
2736+ {"value" : True , "editable" : True },
2737+ self .sg .schema_field_read ("Asset" , field_name , project_2 )[field_name ]["visible" ]
2738+ )
2739+
2740+ # Restore the visibility on the field.
2741+ self .sg .schema_field_update ("Asset" , field_name , {"visible" : True }, project_1 )
2742+ self .assertEqual (
2743+ {"value" : True , "editable" : True },
2744+ self .sg .schema_field_read ("Asset" , field_name , project_1 )[field_name ]["visible" ]
2745+ )
2746+
26812747
26822748def _has_unicode (data ):
26832749 for k , v in data .items ():
0 commit comments