Skip to content

Commit 901478f

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 70c09ef commit 901478f

File tree

4 files changed

+81
-31
lines changed

4 files changed

+81
-31
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: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
import base
77

8+
89
class TestShotgunApiLong(base.LiveTestBase):
9-
10+
1011
def test_automated_find(self):
1112
"""Called find for each entity type and read all fields"""
1213
all_entities = self.sg.schema_entity_read().keys()
@@ -24,66 +25,93 @@ def test_automated_find(self):
2425
if not fields:
2526
print "No fields for %s skipping" % (entity_type,)
2627
continue
27-
28-
#trying to use some different code paths to the other find test
29-
#TODO for our test project, we haven't populated these entities....
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....
3031
order = [{'field_name': fields.keys()[0], 'direction': direction}]
3132
if "project" in fields:
3233
filters = [['project', 'is', self.project]]
3334
else:
3435
filters = []
3536

36-
records = self.sg.find(entity_type, filters, fields=fields.keys(),
37+
records = self.sg.find(entity_type, filters, fields=fields.keys(),
3738
order=order, filter_operator=filter_operator,
3839
limit=limit, page=page)
39-
40+
4041
self.assertTrue(isinstance(records, list))
41-
42+
4243
if filter_operator == "all":
4344
filter_operator = "any"
44-
else:
45+
else:
4546
filter_operator = "all"
4647
if direction == "desc":
4748
direction = "asc"
48-
else:
49+
else:
4950
direction = "desc"
5051
limit = (limit % 5) + 1
5152
page = (page % 3) + 1
52-
5353

5454
def test_schema(self):
5555
"""Called schema functions"""
56-
56+
5757
schema = self.sg.schema_entity_read()
5858
self.assertTrue(schema, dict)
5959
self.assertTrue(len(schema) > 0)
6060

6161
schema = self.sg.schema_read()
6262
self.assertTrue(schema, dict)
6363
self.assertTrue(len(schema) > 0)
64-
64+
6565
schema = self.sg.schema_field_read("Version")
6666
self.assertTrue(schema, dict)
6767
self.assertTrue(len(schema) > 0)
68-
68+
6969
schema = self.sg.schema_field_read("Version", field_name="user")
7070
self.assertTrue(schema, dict)
7171
self.assertTrue(len(schema) > 0)
7272
self.assertTrue("user" in schema)
73-
74-
properties = { "description" : "How many monkeys were needed" }
75-
new_field_name = self.sg.schema_field_create("Version", "number",
76-
"Monkey Count",
73+
74+
properties = {"description": "How many monkeys were needed"}
75+
new_field_name = self.sg.schema_field_create("Version", "number",
76+
"Monkey Count",
7777
properties=properties)
78-
79-
properties = {"description" : "How many monkeys turned up"}
78+
79+
properties = {"description": "How many monkeys turned up"}
8080
ret_val = self.sg.schema_field_update("Version",
81-
new_field_name,
82-
properties)
81+
new_field_name,
82+
properties)
8383
self.assertTrue(ret_val)
84-
84+
8585
ret_val = self.sg.schema_field_delete("Version", new_field_name)
8686
self.assertTrue(ret_val)
87-
88-
if __name__ == '__main__':
87+
88+
def test_schema_with_project(self):
89+
"""Called schema functions"""
90+
91+
project_entity = {'type': 'Project', 'id': 0}
92+
schema = self.sg.schema_entity_read(project_entity)
93+
self.assertTrue(schema, dict)
94+
self.assertTrue(len(schema) > 0)
95+
self.assertTrue('Project' in schema)
96+
self.assertTrue('visible' in schema['Project'])
97+
98+
schema = self.sg.schema_read(project_entity)
99+
self.assertTrue(schema, dict)
100+
self.assertTrue(len(schema) > 0)
101+
self.assertTrue('Version' in schema)
102+
103+
schema = self.sg.schema_field_read('Version', project_entity=project_entity)
104+
self.assertTrue(schema, dict)
105+
self.assertTrue(len(schema) > 0)
106+
self.assertTrue('user' in schema)
107+
self.assertTrue('visible' in schema['user'])
108+
109+
schema = self.sg.schema_field_read('Version', 'user', project_entity)
110+
self.assertTrue(schema, dict)
111+
self.assertTrue(len(schema) > 0)
112+
self.assertTrue('user' in schema)
113+
self.assertTrue('visible' in schema['user'])
114+
115+
116+
if __name__ == '__main__':
89117
base.unittest.main()

0 commit comments

Comments
 (0)