Skip to content

Commit

Permalink
For #28817: FIXED failing tests in older sites due to new features
Browse files Browse the repository at this point in the history
  • Loading branch information
nemoDreamer committed Mar 25, 2015
1 parent 650a20c commit 7a26d76
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 66 deletions.
42 changes: 22 additions & 20 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ def ensure_include_archived_projects(self):
'label': 'include_archived_projects parameter'
})

def ensure_per_project_customization(self):
"""Wrapper for ensure_support"""
return self._ensure_support({
'version': (5, 4, 4),
'label': 'project parameter'
}, True)


def __str__(self):
return "ServerCapabilities: host %s, version %s, is_dev %s"\
Expand Down Expand Up @@ -643,6 +650,15 @@ def _construct_read_parameters(self,
params['sorts'] = sort_list
return params


def _add_project_param(self, params, project_entity):

if project_entity and self.server_caps.ensure_per_project_customization():
params["project"] = project_entity

return params


def summarize(self,
entity_type,
filters,
Expand Down Expand Up @@ -1021,12 +1037,7 @@ def schema_entity_read(self, project_entity=None):

params = {}

if project_entity:
if not self.server_caps.version or self.server_caps.version < (5, 4, 4):
raise ShotgunError("Per project schema operations require server "\
"version 5.4.4 or higher, server is %s" % (self.server_caps.version,))
else:
params["project"] = project_entity
params = self._add_project_param(params, project_entity)

if params:
return self._call_rpc("schema_entity_read", params)
Expand All @@ -1045,13 +1056,8 @@ def schema_read(self, project_entity=None):

params = {}

if project_entity:
if not self.server_caps.version or self.server_caps.version < (5, 4, 4):
raise ShotgunError("Per project schema operations require server "\
"version 5.4.4 or higher, server is %s" % (self.server_caps.version,))
else:
params["project"] = project_entity

params = self._add_project_param(params, project_entity)

if params:
return self._call_rpc("schema_read", params)
else:
Expand All @@ -1078,15 +1084,11 @@ def schema_field_read(self, entity_type, field_name=None, project_entity=None):
params = {
"type": entity_type,
}

if field_name:
params["field_name"] = field_name

if project_entity:
if not self.server_caps.version or self.server_caps.version < (5, 4, 4):
raise ShotgunError("Per project schema operations require server "\
"version 5.4.4 or higher, server is %s" % (self.server_caps.version,))
else:
params["project"] = project_entity

params = self._add_project_param(params, project_entity)

return self._call_rpc("schema_field_read", params)

Expand Down
78 changes: 42 additions & 36 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,57 +1567,63 @@ class TestSessionTokenAuth(base.SessionTokenAuthLiveTestBase):
"""
Testing the session token based authentication method
"""

def test_humanuser_find(self):
"""Called find, find_one for known entities as session token based user"""
filters = []
filters.append(['project', 'is', self.project])
filters.append(['id', 'is', self.version['id']])

fields = ['id']
if self.sg.server_caps.version >= (5, 4, 1):

versions = self.sg.find("Version", filters, fields=fields)
filters = []
filters.append(['project', 'is', self.project])
filters.append(['id', 'is', self.version['id']])

self.assertTrue(isinstance(versions, list))
version = versions[0]
self.assertEqual("Version", version["type"])
self.assertEqual(self.version['id'], version["id"])
fields = ['id']

version = self.sg.find_one("Version", filters, fields=fields)
self.assertEqual("Version", version["type"])
self.assertEqual(self.version['id'], version["id"])
versions = self.sg.find("Version", filters, fields=fields)

self.assertTrue(isinstance(versions, list))
version = versions[0]
self.assertEqual("Version", version["type"])
self.assertEqual(self.version['id'], version["id"])

version = self.sg.find_one("Version", filters, fields=fields)
self.assertEqual("Version", version["type"])
self.assertEqual(self.version['id'], version["id"])

def test_humanuser_upload_thumbnail_for_version(self):
"""simple upload thumbnail for version test as session based token user."""
this_dir, _ = os.path.split(__file__)
path = os.path.abspath(os.path.expanduser(
os.path.join(this_dir,"sg_logo.jpg")))
size = os.stat(path).st_size

# upload thumbnail
thumb_id = self.sg.upload_thumbnail("Version",
self.version['id'], path)
self.assertTrue(isinstance(thumb_id, int))
if self.sg.server_caps.version >= (5, 4, 1):

# check result on version
version_with_thumbnail = self.sg.find_one('Version',
[['id', 'is', self.version['id']]],
fields=['image'])
this_dir, _ = os.path.split(__file__)
path = os.path.abspath(os.path.expanduser(
os.path.join(this_dir,"sg_logo.jpg")))
size = os.stat(path).st_size

self.assertEqual(version_with_thumbnail.get('type'), 'Version')
self.assertEqual(version_with_thumbnail.get('id'), self.version['id'])
# upload thumbnail
thumb_id = self.sg.upload_thumbnail("Version",
self.version['id'], path)
self.assertTrue(isinstance(thumb_id, int))

# check result on version
version_with_thumbnail = self.sg.find_one('Version',
[['id', 'is', self.version['id']]],
fields=['image'])

h = Http(".cache")
thumb_resp, content = h.request(version_with_thumbnail.get('image'), "GET")
self.assertEqual(thumb_resp['status'], '200')
self.assertEqual(thumb_resp['content-type'], 'image/jpeg')
self.assertEqual(version_with_thumbnail.get('type'), 'Version')
self.assertEqual(version_with_thumbnail.get('id'), self.version['id'])

# clear thumbnail
response_clear_thumbnail = self.sg.update("Version",
self.version['id'], {'image':None})
expected_clear_thumbnail = {'id': self.version['id'], 'image': None, 'type': 'Version'}
self.assertEqual(expected_clear_thumbnail, response_clear_thumbnail)

h = Http(".cache")
thumb_resp, content = h.request(version_with_thumbnail.get('image'), "GET")
self.assertEqual(thumb_resp['status'], '200')
self.assertEqual(thumb_resp['content-type'], 'image/jpeg')

# clear thumbnail
response_clear_thumbnail = self.sg.update("Version",
self.version['id'], {'image':None})
expected_clear_thumbnail = {'id': self.version['id'], 'image': None, 'type': 'Version'}
self.assertEqual(expected_clear_thumbnail, response_clear_thumbnail)


class TestProjectLastAccessedByCurrentUser(base.LiveTestBase):
Expand Down
24 changes: 14 additions & 10 deletions tests/test_api_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,39 @@ def test_schema(self):
self.assertTrue(ret_val)

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

project_entity = {'type': 'Project', 'id': 0}

if not self.sg.server_caps.version or self.sg.server_caps.version < (5, 4, 4):

# server does not support this!
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_entity_read, {'type': 'Project', 'id': 0})
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_read, {'type': 'Project', 'id': 0})
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_field_read, 'Version', None, {'type': 'Project', 'id': 0})
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_field_read, 'Version', 'user', {'type': 'Project', 'id': 0})

self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_entity_read, project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_read, project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_field_read, 'Version', None, project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_field_read, 'Version', 'user', project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_entity_read, project_entity)

else:
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)
Expand Down

0 comments on commit 7a26d76

Please sign in to comment.