SG-20154 Add Retries on 503 Errors when uploading to S3 in Shotgun py… · PhoenixDigitalFX/python-api@e640bae · GitHub
Skip to content

Commit e640bae

Browse files
authored
SG-20154 Add Retries on 503 Errors when uploading to S3 in Shotgun python-api (shotgunsoftware#263)
* Add the 503 retries in the internal function who maker the S3 uploads. * Mock the S3 response with a expected HTTPError exception, for test 503 responses are retried when uploading to S3. * Adding side_effect parameter to the mock object. * Add comment in the _setup_mock() _make_upload_request definition. * Rename test and add expected HTTPError exception error message to the assertion.
1 parent 6a48fb9 commit e640bae

3 files changed

Lines changed: 78 additions & 15 deletions

File tree

shotgun_api3/shotgun.py

Lines changed: 43 additions & 12 deletions

tests/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from shotgun_api3.shotgun import json
1010
from shotgun_api3.shotgun import ServerCapabilities
1111
from shotgun_api3.lib import six
12+
from shotgun_api3.lib.six.moves import urllib
1213

1314
if six.PY2:
1415
from shotgun_api3.lib.six.moves.configparser import SafeConfigParser as ConfigParser
@@ -128,7 +129,17 @@ def _setup_mock(self):
128129
# eaiser than mocking the http connection + response
129130
self.sg._http_request = mock.Mock(spec=api.Shotgun._http_request,
130131
return_value=((200, "OK"), {}, None))
131-
132+
# Replace the function used to make the final call to the S3 server, and simulate
133+
# the exception HTTPError raised with 503 status errors
134+
self.sg._make_upload_request = mock.Mock(spec=api.Shotgun._make_upload_request,
135+
side_effect = urllib.error.HTTPError(
136+
"url",
137+
503,
138+
"The server is currently down or to busy to reply."
139+
"Please try again later.",
140+
{},
141+
None
142+
))
132143
# also replace the function that is called to get the http connection
133144
# to avoid calling the server. OK to return a mock as we will not use
134145
# it

tests/test_client.py

Lines changed: 23 additions & 2 deletions

0 commit comments

Comments
 (0)