Skip to content

Adds per-project visibility querying on schema methods #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Integration and unit tests are provided.

## Changelog

**v3.0.18 - 2015 Mar 13**

+ Add ability to query the per-project visibility status for entities, fields and statuses. (requires Shotgun server >= v5.4.4)

**v3.0.17 - 2014 Jul 10**

+ Add ability to update last_accessed_by_current_user on Project.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='shotgun_api3',
version='3.0.17',
version='3.0.18',
description='Shotgun Python API ',
long_description=readme,
author='Shotgun Software',
Expand Down
44 changes: 37 additions & 7 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

# ----------------------------------------------------------------------------
# Version
__version__ = "3.0.18.dev"
__version__ = "3.0.18"

# ----------------------------------------------------------------------------
# Errors
Expand Down Expand Up @@ -945,23 +945,47 @@ def followers(self, entity):

return self._call_rpc('followers', params)

def schema_entity_read(self):
def schema_entity_read(self, project_entity=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! It would be great if we could have a `:param: style docstring for this new parameter - just for consistency with other methods! Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, agree, will do

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers!

"""Gets all active entities defined in the schema.

:param dict project_entity: Optional, if set, each field's visibility is reported accordingly
to the specified project's current visibility settings.
If None, all fields are reported as visible.

:returns: dict of Entity Type to dict containing the display name.
"""

return self._call_rpc("schema_entity_read", None)
params = {}

if project_entity:
params["project"] = project_entity

def schema_read(self):
if params:
return self._call_rpc("schema_entity_read", params)
else:
return self._call_rpc("schema_entity_read", None)

def schema_read(self, project_entity=None):
"""Gets the schema for all fields in all entities.

:param dict project_entity: Optional, if set, each field's visibility is reported accordingly
to the specified project's current visibility settings.
If None, all fields are reported as visible.

:returns: nested dicts
"""

return self._call_rpc("schema_read", None)
params = {}

if project_entity:
params["project"] = project_entity

def schema_field_read(self, entity_type, field_name=None):
if params:
return self._call_rpc("schema_read", params)
else:
return self._call_rpc("schema_read", None)

def schema_field_read(self, entity_type, field_name=None, project_entity=None):
"""Gets all schema for fields in the specified entity_type or one
field.

Expand All @@ -972,14 +996,20 @@ def schema_field_read(self, entity_type, field_name=None):
definition for. If not supplied all fields for the entity type are
returned.

:param dict project_entity: Optional, if set, each field's visibility is reported accordingly
to the specified project's current visibility settings.
If None, all fields are reported as visible.

:returns: dict of field name to nested dicts which describe the field
"""

params = {
"type" : entity_type,
"type": entity_type,
}
if field_name:
params["field_name"] = field_name
if project_entity:
params["project"] = project_entity

return self._call_rpc("schema_field_read", params)

Expand Down
73 changes: 51 additions & 22 deletions tests/test_api_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import base
import random


class TestShotgunApiLong(base.LiveTestBase):

def test_automated_find(self):
"""Called find for each entity type and read all fields"""
all_entities = self.sg.schema_entity_read().keys()
Expand All @@ -25,57 +26,56 @@ def test_automated_find(self):
if not fields:
print "No fields for %s skipping" % (entity_type,)
continue
#trying to use some different code paths to the other find test
#TODO for our test project, we haven't populated these entities....

# trying to use some different code paths to the other find test
# TODO for our test project, we haven't populated these entities....
order = [{'field_name': fields.keys()[0], 'direction': direction}]
if "project" in fields:
filters = [['project', 'is', self.project]]
else:
filters = []

records = self.sg.find(entity_type, filters, fields=fields.keys(),
records = self.sg.find(entity_type, filters, fields=fields.keys(),
order=order, filter_operator=filter_operator,
limit=limit, page=page)

self.assertTrue(isinstance(records, list))

if filter_operator == "all":
filter_operator = "any"
else:
else:
filter_operator = "all"
if direction == "desc":
direction = "asc"
else:
else:
direction = "desc"
limit = (limit % 5) + 1
page = (page % 3) + 1


def test_schema(self):
"""Called schema functions"""

schema = self.sg.schema_entity_read()
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)

schema = self.sg.schema_read()
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)

schema = self.sg.schema_field_read("Version")
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)

schema = self.sg.schema_field_read("Version", field_name="user")
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue("user" in schema)

# An explantion is in order here. the field code that is created in shotgun is based on the human display name
# An explanation is in order here. the field code that is created in shotgun is based on the human display name
# that is provided , so for example "Money Count" would generate the field code 'sg_monkey_count' . The field
# that is created in this test is retired at the end of the test but when this test is run again against
# the same database ( which happens on our Continous Integration server ) trying to create a new field
# the same database ( which happens on our Continuous Integration server ) trying to create a new field
# called "Monkey Count" will now fail due to the new Delete Field Forever features we have added to shotgun
# since there will a retired field called sg_monkey_count. The old behavior was to go ahead and create a new
# "Monkey Count" field with a field code with an incremented number of the end like sg_monkey_count_1. The new
Expand All @@ -87,15 +87,44 @@ def test_schema(self):
properties = { "description" : "How many monkeys were needed" }
new_field_name = self.sg.schema_field_create("Version", "number", human_field_name,
properties=properties)
properties = {"description" : "How many monkeys turned up"}

properties = {"description": "How many monkeys turned up"}
ret_val = self.sg.schema_field_update("Version",
new_field_name,
properties)
new_field_name,
properties)
self.assertTrue(ret_val)

ret_val = self.sg.schema_field_delete("Version", new_field_name)
self.assertTrue(ret_val)

if __name__ == '__main__':

def test_schema_with_project(self):
"""Called schema functions"""

project_entity = {'type': 'Project', 'id': 0}
schema = self.sg.schema_entity_read(project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('Project' in schema)
self.assertTrue('visible' in schema['Project'])

schema = self.sg.schema_read(project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('Version' in schema)
self.assertFalse('visible' in schema.keys())

schema = self.sg.schema_field_read('Version', project_entity=project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('user' in schema)
self.assertTrue('visible' in schema['user'])

schema = self.sg.schema_field_read('Version', 'user', project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('user' in schema)
self.assertTrue('visible' in schema['user'])


if __name__ == '__main__':
base.unittest.main()