Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #446 from happyspace/master
Browse files Browse the repository at this point in the history
Python 3 error: step2_exchange confusing unicode/bytes.
  • Loading branch information
nathanielmanistaatgoogle committed Mar 3, 2016
2 parents f09af42 + 6a273d6 commit 15c945f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oauth2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ def step2_exchange(self, code=None, http=None, device_flow_info=None):

if code is None:
code = device_flow_info.device_code
elif not isinstance(code, six.string_types):
elif not isinstance(code, (six.string_types, six.binary_type)):
if 'code' not in code:
raise FlowExchangeError(code.get(
'error', 'No code was supplied in the query parameters.'))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from oauth2client.client import save_to_well_known_file
from oauth2client.clientsecrets import _loadfile
from oauth2client.service_account import ServiceAccountCredentials
from oauth2client._helpers import _to_bytes

__author__ = 'jcgregorio@google.com (Joe Gregorio)'

Expand Down Expand Up @@ -1201,6 +1202,26 @@ def test_exchange_success(self):
self.assertEqual('dummy_revoke_uri', credentials.revoke_uri)
self.assertEqual(set(['foo']), credentials.scopes)

def test_exchange_success_binary_code(self):
binary_code = b'some random code'
access_token = 'SlAV32hkKG'
expires_in = '3600'
refresh_token = '8xLOxBtZp8'
revoke_uri = 'dummy_revoke_uri'

payload = ('{'
' "access_token":"' + access_token + '",'
' "expires_in":' + expires_in + ','
' "refresh_token":"' + refresh_token + '"'
'}')
http = HttpMockSequence([({'status': '200'}, _to_bytes(payload))])
credentials = self.flow.step2_exchange(binary_code, http=http)
self.assertEqual(access_token, credentials.access_token)
self.assertIsNotNone(credentials.token_expiry)
self.assertEqual(refresh_token, credentials.refresh_token)
self.assertEqual(revoke_uri, credentials.revoke_uri)
self.assertEqual(set(['foo']), credentials.scopes)

def test_exchange_dictlike(self):
class FakeDict(object):
def __init__(self, d):
Expand Down

0 comments on commit 15c945f

Please sign in to comment.