8000 fix: allow API redirect responses (#540) · twilio/twilio-python@65adee6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65adee6

Browse files
author
childish-sambino
authored
fix: allow API redirect responses (#540)
Fetching a BulkExport for a single day returns a `307` with the AWS URL for the file. With this change, the URL will now be included in the response.
1 parent d1b2dcc commit 65adee6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

tests/unit/base/test_version.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def get_instance(self, payload):
1212
return payload
1313

1414

15-
class VersionTestCase(IntegrationTestCase):
15+
class StreamTestCase(IntegrationTestCase):
1616
def setUp(self):
17-
super(VersionTestCase, self).setUp()
17+
super(StreamTestCase, self).setUp()
1818

1919
self.holodeck.mock(Response(
2020
200,
@@ -64,3 +64,17 @@ def test_stream_page_limit(self):
6464
messages = list(self.version.stream(self.page, page_limit=1))
6565

6666
self.assertEqual(len(messages), 2)
67+
68+
69+
class VersionTestCase(IntegrationTestCase):
70+
def test_fetch_redirect(self):
71+
self.holodeck.mock(Response(
72+
307,
73+
'{"redirect_to": "some_place"}'
74+
), Request(url='https://messaging.twilio.com/v1/Deactivations'))
75+
response = self.client.messaging.v1.fetch(
76+
method='GET',
77+
uri='/Deactivations'
78+
)
79+
80+
self.assertIsNotNone(response)

twilio/base/version.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def fetch(self, method, uri, params=None, data=None, headers=None, auth=None, ti
8080
allow_redirects=allow_redirects,
8181
)
8282

83-
if response.status_code < 200 or response.status_code >= 300:
83+
# Note that 3XX response codes are allowed for fetches.
84+
if response.status_code < 200 or response.status_code >= 400:
8485
raise self.exception(method, uri, response, 'Unable to fetch record')
8586

8687
return json.loads(response.text)

0 commit comments

Comments
 (0)
0