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

Python 3 error: step2_exchange confusing unicode/bytes #446

Merged
merged 1 commit into from
Mar 3, 2016

Conversation

happyspace
Copy link
Contributor

In python 3, the code received from the browser will be binary instead of a string. Expand the API for oauth_flow.step2_exchange(code) to allow this value to be passed in as is rather than decoding.

for example:
credentials = self.flow.step2_exchange(b'some random code')

test:
tox -e py34 -- tests.test_client:OAuth2WebServerFlowTest.test_exchange_success_binary_code

resolves: #443

http = HttpMockSequence([({'status': '200'}, payload)])
credentials = self.flow.step2_exchange(b'some random code', http=http)
self.assertEqual('SlAV32hkKG', credentials.access_token)
self.assertNotEqual(None, credentials.token_expiry)

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Feb 29, 2016

LGTM pending @nathanielmanistaatgoogle comment

@@ -1201,6 +1201,21 @@ 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):
payload = (b'{'
b' "access_token":"SlAV32hkKG",'

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@nathanielmanistaatgoogle
Copy link
Contributor

Please amend your commit message to conform to these guidelines.

@nathanielmanistaatgoogle
Copy link
Contributor

Closed?

@happyspace happyspace reopened this Mar 1, 2016
@happyspace
Copy link
Contributor Author

Sorry I was updating the comment and wiped everything out with a force push. grrr...

Whew are we back? I updated the comment as per guidelines.

happyspace added a commit to happyspace/oauth2client-1 that referenced this pull request Mar 1, 2016
As per suggestions nathanielmanistaatgoogle, create local constants for variables used in test.
Use _to_bytes() from _helper to convert to bytes.

resolves: googleapis#446
http = HttpMockSequence([({'status': '200'}, _to_bytes(payload))])
credentials = self.flow.step2_exchange(binary_code, http=http)
self.assertEqual(access_token, credentials.access_token)
self.assertNotEqual(None, credentials.token_expiry)

This comment was marked as spam.

@nathanielmanistaatgoogle
Copy link
Contributor

Please squash commits with each round of code review back-and-forth. Are you sure that your commit message summary line is fifty characters or fewer?

happyspace added a commit to happyspace/oauth2client-1 that referenced this pull request Mar 1, 2016
Use self.assertIsNotNone for not None check.

resolves: googleapis#446
In python 3, the code received from the browser will be binary instead of a string. Expand the API for oauth_flow.step2_exchange(code) to allow this value to be passed as is rather than decoding.

for example:
credentials = self.flow.step2_exchange(b'some random code')

test:
tox -e py34  -- tests.test_client:OAuth2WebServerFlowTest.test_exchange_success_binary_code

resolves:  googleapis#443, googleapis#446
nathanielmanistaatgoogle added a commit that referenced this pull request Mar 3, 2016
Python 3 error: step2_exchange confusing unicode/bytes.
@nathanielmanistaatgoogle nathanielmanistaatgoogle merged commit 15c945f into googleapis:master Mar 3, 2016
@theacodes theacodes mentioned this pull request Apr 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 3 error: step2_exchange confusing unicode/bytes
4 participants