Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow API redirect responses #540

Merged
merged 1 commit into from
Sep 21, 2020
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
18 changes: 16 additions & 2 deletions tests/unit/base/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def get_instance(self, payload):
return payload


class VersionTestCase(IntegrationTestCase):
class StreamTestCase(IntegrationTestCase):
def setUp(self):
super(VersionTestCase, self).setUp()
super(StreamTestCase, self).setUp()

self.holodeck.mock(Response(
200,
Expand Down Expand Up @@ -64,3 +64,17 @@ def test_stream_page_limit(self):
messages = list(self.version.stream(self.page, page_limit=1))

self.assertEqual(len(messages), 2)


class VersionTestCase(IntegrationTestCase):
def test_fetch_redirect(self):
self.holodeck.mock(Response(
307,
'{"redirect_to": "some_place"}'
), Request(url='https://messaging.twilio.com/v1/Deactivations'))
response = self.client.messaging.v1.fetch(
method='GET',
uri='/Deactivations'
)

self.assertIsNotNone(response)
3 changes: 2 additions & 1 deletion twilio/base/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def fetch(self, method, uri, params=None, data=None, headers=None, auth=None, ti
allow_redirects=allow_redirects,
)

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

return json.loads(response.text)
Expand Down