66import base
77import random
88
9+
910class TestShotgunApiLong (base .LiveTestBase ):
10-
11+
1112 def test_automated_find (self ):
1213 """Called find for each entity type and read all fields"""
1314 all_entities = self .sg .schema_entity_read ().keys ()
@@ -25,57 +26,56 @@ def test_automated_find(self):
2526 if not fields :
2627 print "No fields for %s skipping" % (entity_type ,)
2728 continue
28-
29- #trying to use some different code paths to the other find test
30- #TODO for our test project, we haven't populated these entities....
29+
30+ # trying to use some different code paths to the other find test
31+ # TODO for our test project, we haven't populated these entities....
3132 order = [{'field_name' : fields .keys ()[0 ], 'direction' : direction }]
3233 if "project" in fields :
3334 filters = [['project' , 'is' , self .project ]]
3435 else :
3536 filters = []
3637
37- records = self .sg .find (entity_type , filters , fields = fields .keys (),
38+ records = self .sg .find (entity_type , filters , fields = fields .keys (),
3839 order = order , filter_operator = filter_operator ,
3940 limit = limit , page = page )
40-
41+
4142 self .assertTrue (isinstance (records , list ))
42-
43+
4344 if filter_operator == "all" :
4445 filter_operator = "any"
45- else :
46+ else :
4647 filter_operator = "all"
4748 if direction == "desc" :
4849 direction = "asc"
49- else :
50+ else :
5051 direction = "desc"
5152 limit = (limit % 5 ) + 1
5253 page = (page % 3 ) + 1
53-
5454
5555 def test_schema (self ):
5656 """Called schema functions"""
57-
57+
5858 schema = self .sg .schema_entity_read ()
5959 self .assertTrue (schema , dict )
6060 self .assertTrue (len (schema ) > 0 )
6161
6262 schema = self .sg .schema_read ()
6363 self .assertTrue (schema , dict )
6464 self .assertTrue (len (schema ) > 0 )
65-
65+
6666 schema = self .sg .schema_field_read ("Version" )
6767 self .assertTrue (schema , dict )
6868 self .assertTrue (len (schema ) > 0 )
69-
69+
7070 schema = self .sg .schema_field_read ("Version" , field_name = "user" )
7171 self .assertTrue (schema , dict )
7272 self .assertTrue (len (schema ) > 0 )
7373 self .assertTrue ("user" in schema )
7474
75- # An explantion is in order here. the field code that is created in shotgun is based on the human display name
75+ # An explanation is in order here. the field code that is created in shotgun is based on the human display name
7676 # that is provided , so for example "Money Count" would generate the field code 'sg_monkey_count' . The field
7777 # that is created in this test is retired at the end of the test but when this test is run again against
78- # the same database ( which happens on our Continous Integration server ) trying to create a new field
78+ # the same database ( which happens on our Continuous Integration server ) trying to create a new field
7979 # called "Monkey Count" will now fail due to the new Delete Field Forever features we have added to shotgun
8080 # since there will a retired field called sg_monkey_count. The old behavior was to go ahead and create a new
8181 # "Monkey Count" field with a field code with an incremented number of the end like sg_monkey_count_1. The new
@@ -87,15 +87,44 @@ def test_schema(self):
8787 properties = { "description" : "How many monkeys were needed" }
8888 new_field_name = self .sg .schema_field_create ("Version" , "number" , human_field_name ,
8989 properties = properties )
90-
91- properties = {"description" : "How many monkeys turned up" }
90+
91+ properties = {"description" : "How many monkeys turned up" }
9292 ret_val = self .sg .schema_field_update ("Version" ,
93- new_field_name ,
94- properties )
93+ new_field_name ,
94+ properties )
9595 self .assertTrue (ret_val )
96-
96+
9797 ret_val = self .sg .schema_field_delete ("Version" , new_field_name )
9898 self .assertTrue (ret_val )
99-
100- if __name__ == '__main__' :
99+
100+ def test_schema_with_project (self ):
101+ """Called schema functions"""
102+
103+ project_entity = {'type' : 'Project' , 'id' : 0 }
104+ schema = self .sg .schema_entity_read (project_entity )
105+ self .assertTrue (schema , dict )
106+ self .assertTrue (len (schema ) > 0 )
107+ self .assertTrue ('Project' in schema )
108+ self .assertTrue ('visible' in schema ['Project' ])
109+
110+ schema = self .sg .schema_read (project_entity )
111+ self .assertTrue (schema , dict )
112+ self .assertTrue (len (schema ) > 0 )
113+ self .assertTrue ('Version' in schema )
114+ self .assertFalse ('visible' in schema .keys ())
115+
116+ schema = self .sg .schema_field_read ('Version' , project_entity = project_entity )
117+ self .assertTrue (schema , dict )
118+ self .assertTrue (len (schema ) > 0 )
119+ self .assertTrue ('user' in schema )
120+ self .assertTrue ('visible' in schema ['user' ])
121+
122+ schema = self .sg .schema_field_read ('Version' , 'user' , project_entity )
123+ self .assertTrue (schema , dict )
124+ self .assertTrue (len (schema ) > 0 )
125+ self .assertTrue ('user' in schema )
126+ self .assertTrue ('visible' in schema ['user' ])
127+
128+
129+ if __name__ == '__main__' :
101130 base .unittest .main ()
0 commit comments