Skip to content

Commit a1b0562

Browse files
For #27860, update the python API to support project customization
- updated schema_.*read methods for project argument - add new unit tests to validate querying per project - updated README - updated date in changelog
1 parent 758d0c1 commit a1b0562

File tree

4 files changed

+79
-29
lines changed

4 files changed

+79
-29
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ Integration and unit tests are provided.
5353

5454
## Changelog
5555

56+
**v3.0.18 - 2015 Mar 11
57+
58+
+ Add ability to query the per-project visibility status for entities, fields and statuses. (requires Shotgun server >= v5.4.4)
59+
5660
**v3.0.17 - 2014 Jul 10**
5761

5862
+ Add ability to update last_accessed_by_current_user on Project.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='shotgun_api3',
20-
version='3.0.17',
20+
version='3.0.18',
2121
description='Shotgun Python API ',
2222
long_description=readme,
2323
author='Shotgun Software',

shotgun_api3/shotgun.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,23 +945,39 @@ def followers(self, entity):
945945

946946
return self._call_rpc('followers', params)
947947

948-
def schema_entity_read(self):
948+
def schema_entity_read(self, project_entity=None):
949949
"""Gets all active entities defined in the schema.
950950
951951
:returns: dict of Entity Type to dict containing the display name.
952952
"""
953953

954-
return self._call_rpc("schema_entity_read", None)
954+
params = {}
955+
956+
if project_entity:
957+
params["project"] = project_entity
958+
959+
if params:
960+
return self._call_rpc("schema_entity_read", params)
961+
else:
962+
return self._call_rpc("schema_entity_read", None)
955963

956-
def schema_read(self):
964+
def schema_read(self, project_entity=None):
957965
"""Gets the schema for all fields in all entities.
958966
959967
:returns: nested dicts
960968
"""
961969

962-
return self._call_rpc("schema_read", None)
970+
params = {}
963971

964-
def schema_field_read(self, entity_type, field_name=None):
972+
if project_entity:
973+
params["project"] = project_entity
974+
975+
if params:
976+
return self._call_rpc("schema_read", params)
977+
else:
978+
return self._call_rpc("schema_read", None)
979+
980+
def schema_field_read(self, entity_type, field_name=None, project_entity=None):
965981
"""Gets all schema for fields in the specified entity_type or one
966982
field.
967983
@@ -976,10 +992,12 @@ def schema_field_read(self, entity_type, field_name=None):
976992
"""
977993

978994
params = {
979-
"type" : entity_type,
995+
"type": entity_type,
980996
}
981997
if field_name:
982998
params["field_name"] = field_name
999+
if project_entity:
1000+
params["project"] = project_entity
9831001

9841002
return self._call_rpc("schema_field_read", params)
9851003

tests/test_api_long.py

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import base
77
import random
88

9+
910
class 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,43 @@ 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+
115+
schema = self.sg.schema_field_read('Version', project_entity=project_entity)
116+
self.assertTrue(schema, dict)
117+
self.assertTrue(len(schema) > 0)
118+
self.assertTrue('user' in schema)
119+
self.assertTrue('visible' in schema['user'])
120+
121+
schema = self.sg.schema_field_read('Version', 'user', project_entity)
122+
self.assertTrue(schema, dict)
123+
self.assertTrue(len(schema) > 0)
124+
self.assertTrue('user' in schema)
125+
self.assertTrue('visible' in schema['user'])
126+
127+
128+
if __name__ == '__main__':
101129
base.unittest.main()

0 commit comments

Comments
 (0)