-
Notifications
You must be signed in to change notification settings - Fork 430
Python 3 error: step2_exchange confusing unicode/bytes #446
Conversation
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.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Please amend your commit message to conform to these guidelines. |
Closed? |
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. |
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.
This comment was marked as spam.
Sorry, something went wrong.
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? |
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
Python 3 error: step2_exchange confusing unicode/bytes.
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