Skip to content

Commit 1cf6c3b

Browse files
authored
For SG-13320: shared_thumbnail raises a specific error when transient thumbnail detected
1 parent 7d2e224 commit 1cf6c3b

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Shotgun Python API Changelog
44

55
Here you can see the full list of changes between each Python API release.
66

7+
v3.2.1 (TBD)
8+
=====================
9+
- Returns a specific error from 'share_thumbnail' when the source thumbnail is a 'transient' thumbnail.
10+
711
v3.2.0 (2019 Sept 23)
812
=====================
913
- Adds a new ``project_entity`` parameter to ``schema_field_update`` that allows to modify field visibility for a given project.

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ Additionally, when testing locally, tests should be run for both python 2 and py
100100

101101
Integration and unit tests are provided.
102102

103-
- All tests require the [nose unit testing tools](http://nose.readthedocs.org), and a `tests/config` file (you can copy an example from `tests/example_config`).
104-
- Tests can be run individually like this: `nosetest tests/test_client.py`
103+
- All tests require:
104+
- The [nose unit testing tools](http://nose.readthedocs.org),
105+
- The [nose-exclude nose plugin](https://pypi.org/project/nose-exclude/)
106+
- (Note: Running `pip install -r tests/ci_requirements.txt` will install this package)
107+
- A `tests/config` file (you can copy an example from `tests/example_config`).
108+
- Tests can be run individually like this: `nosetests --config="nose.cfg" tests/test_client.py`
109+
- Make sure to not forget the `--config="nose.cfg"` option. This option tells nose to use our config file. This will exclude python 2- and 3-specific files in the `/lib` directory, preventing a failure from being reported by nose for compilation due to incompatible syntax in those files.
105110
- `test_client` and `tests_unit` use mock server interaction and do not require a Shotgun instance to be available (no modifications to `tests/config` are necessary).
106111
- `test_api` and `test_api_long` *do* require a Shotgun instance, with a script key available for the tests. The server and script user values must be supplied in the `tests/config` file. The tests will add test data to your server based on information in your config. This data will be manipulated by the tests, and should not be used for other purposes.
107112
- To run all of the tests, use the shell script `run-tests`.

shotgun_api3/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
99
# not expressly granted therein are reserved by Shotgun Software Inc.
1010

11-
from .shotgun import (Shotgun, ShotgunError, ShotgunFileDownloadError, Fault, # noqa unused imports
11+
from .shotgun import (Shotgun, ShotgunError, ShotgunFileDownloadError, # noqa unused imports
12+
ShotgunThumbnailNotReady, Fault,
1213
AuthenticationFault, MissingTwoFactorAuthenticationFault,
1314
UserCredentialsNotAllowedForSSOAuthenticationFault,
1415
ProtocolError, ResponseError, Error, __version__)

shotgun_api3/shotgun.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _is_mimetypes_broken():
117117

118118
# ----------------------------------------------------------------------------
119119
# Version
120-
__version__ = "3.2.0"
120+
__version__ = "3.2.1.dev"
121121

122122
# ----------------------------------------------------------------------------
123123
# Errors
@@ -137,6 +137,13 @@ class ShotgunFileDownloadError(ShotgunError):
137137
pass
138138

139139

140+
class ShotgunThumbnailNotReady(ShotgunError):
141+
"""
142+
Exception for when trying to use a 'pending thumbnail' (aka transient thumbnail) in an operation
143+
"""
144+
pass
145+
146+
140147
class Fault(ShotgunError):
141148
"""
142149
Exception when server-side exception detected.
@@ -2271,14 +2278,16 @@ def share_thumbnail(self, entities, thumbnail_path=None, source_entity=None,
22712278

22722279
result = self._send_form(url, params)
22732280

2274-
if not result.startswith("1"):
2275-
raise ShotgunError("Unable to share thumbnail: %s" % result)
2276-
else:
2281+
if result.startswith("1:"):
22772282
# clearing thumbnail returns no attachment_id
22782283
try:
22792284
attachment_id = int(result.split(":", 2)[1].split("\n", 1)[0])
22802285
except ValueError:
22812286
attachment_id = None
2287+
elif result.startswith("2"):
2288+
raise ShotgunThumbnailNotReady("Unable to share thumbnail: %s" % result)
2289+
else:
2290+
raise ShotgunError("Unable to share thumbnail: %s" % result)
22822291

22832292
return attachment_id
22842293

tests/test_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,28 @@ def share_thumbnail_retry(*args, **kwargs):
604604
self.assertRaises(shotgun_api3.ShotgunError, self.sg.share_thumbnail,
605605
[self.shot, self.asset])
606606

607+
@patch('shotgun_api3.Shotgun._send_form')
608+
def test_share_thumbnail_not_ready(self, mock_send_form):
609+
"""throw an exception if trying to share a transient thumbnail"""
610+
611+
mock_send_form.method.assert_called_once()
612+
mock_send_form.return_value = ("2"
613+
"\nsource_entity image is a transient thumbnail that cannot be shared. "
614+
"Try again later, when the final thumbnail is available\n")
615+
616+
self.assertRaises(shotgun_api3.ShotgunThumbnailNotReady, self.sg.share_thumbnail,
617+
[self.version, self.shot], source_entity=self.asset)
618+
619+
@patch('shotgun_api3.Shotgun._send_form')
620+
def test_share_thumbnail_returns_error(self, mock_send_form):
621+
"""throw an exception if server returns an error code"""
622+
623+
mock_send_form.method.assert_called_once()
624+
mock_send_form.return_value = "1\nerror message.\n"
625+
626+
self.assertRaises(shotgun_api3.ShotgunError, self.sg.share_thumbnail,
627+
[self.version, self.shot], source_entity=self.asset)
628+
607629
def test_deprecated_functions(self):
608630
"""Deprecated functions raise errors"""
609631
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema, "foo")

0 commit comments

Comments
 (0)