Skip to content
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
20 changes: 20 additions & 0 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,26 @@ def get_session_token(self):

return session_token

def preferences_read(self, prefs=None):
"""
Get a subset of the site preferences.

>>> sg.preferences_read()
{
"pref_name": "pref value"
}
:param list prefs: An optional list of preference names to return.
:returns: Dictionary of preferences and their values.
:rtype: dict
"""
if self.server_caps.version and self.server_caps.version < (7, 10, 0):
raise ShotgunError("preferences_read requires server version 7.10.0 or "\
"higher, server is %s" % (self.server_caps.version,))

prefs = prefs or []

return self._call_rpc("preferences_read", { "prefs": prefs })

def _build_opener(self, handler):
"""
Build urllib2 opener with appropriate proxy handler.
Expand Down
60 changes: 51 additions & 9 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,48 @@ def test_work_schedule(self):
work_schedule['2012-01-04'] = {"reason": "USER_EXCEPTION", "working": False, "description": "Artist Holiday"}
self.assertEqual(work_schedule, resp)

def test_preferences_read(self):
# Only run the tests on a server with the feature.
if not self.sg.server_caps.version or self.sg.server_caps.version < (7, 10, 0):
return

# all prefs
resp = self.sg.preferences_read()

expected = {
'date_component_order': 'month_day',
'format_currency_fields_decimal_options': '$1,000.99',
'format_currency_fields_display_dollar_sign': False,
'format_currency_fields_negative_options': '- $1,000',
'format_date_fields': '08/04/22 OR 04/08/22 (depending on the Month order preference)',
'format_float_fields': '9,999.99',
'format_float_fields_rounding': '9.999999',
'format_footage_fields': '10-05',
'format_number_fields': '1,000',
'format_time_hour_fields': '12 hour',
'support_local_storage': False
}
self.assertEqual(expected, resp)

# all filtered
resp = self.sg.preferences_read(['date_component_order', 'support_local_storage'])

expected = {
'date_component_order': 'month_day',
'support_local_storage': False
}
self.assertEqual(expected, resp)

# all filtered with invalid pref
resp = self.sg.preferences_read(['date_component_order', 'support_local_storage', 'email_notifications'])

expected = {
'date_component_order': 'month_day',
'support_local_storage': False
}
self.assertEqual(expected, resp)


class TestDataTypes(base.LiveTestBase):
'''Test fields representing the different data types mapped on the server side.

Expand Down Expand Up @@ -1543,18 +1585,18 @@ def test_following(self):
[["id","is",self.task["id"]]],
["project.Project.id"])["project.Project.id"]
project_count = 2 if shot_project_id == task_project_id else 1
result = self.sg.following(self.human_user,
result = self.sg.following(self.human_user,
project={"type":"Project", "id":shot_project_id})
self.assertEqual( project_count, len(result) )
result = self.sg.following(self.human_user,
result = self.sg.following(self.human_user,
project={"type":"Project", "id":task_project_id})
self.assertEqual( project_count, len(result) )
result = self.sg.following(self.human_user,
project={"type":"Project", "id":shot_project_id},
result = self.sg.following(self.human_user,
project={"type":"Project", "id":shot_project_id},
entity_type="Shot")
self.assertEqual( 1, len(result) )
result = self.sg.following(self.human_user,
project={"type":"Project", "id":task_project_id},
result = self.sg.following(self.human_user,
project={"type":"Project", "id":task_project_id},
entity_type="Task")
self.assertEqual( 1, len(result) )

Expand Down Expand Up @@ -1701,7 +1743,7 @@ def test_upload_empty_file(self):
path = os.path.abspath(os.path.expanduser(os.path.join(this_dir,"empty.txt")))
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload, 'Version', 123, path)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload_thumbnail, 'Version', 123, path)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload_filmstrip_thumbnail, 'Version',
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload_filmstrip_thumbnail, 'Version',
123, path)

def test_upload_missing_file(self):
Expand All @@ -1711,7 +1753,7 @@ def test_upload_missing_file(self):
path = "/path/to/nowhere/foo.txt"
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload, 'Version', 123, path)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload_thumbnail, 'Version', 123, path)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload_filmstrip_thumbnail, 'Version',
self.assertRaises(shotgun_api3.ShotgunError, self.sg.upload_filmstrip_thumbnail, 'Version',
123, path)

# def test_malformed_response(self):
Expand Down Expand Up @@ -2525,7 +2567,7 @@ def _has_unicode(data):

def _get_path(url):
"""Returns path component of a url without the sheme, host, query, anchor, or any other
additional elements.
additional elements.
For example, the url "https://foo.shotgunstudio.com/page/2128#Shot_1190_sr10101_034"
returns "/page/2128"
"""
Expand Down