diff options
author | Eddie Warner <happyspace@gmail.com> | 2016-03-01 12:05:18 -0800 |
---|---|---|
committer | Eddie Warner <happyspace@gmail.com> | 2016-03-01 15:02:56 -0800 |
commit | 6a273d678b23b63845e636c0ed6550ce0c23616a (patch) | |
tree | 126c3f53c66db8b19e7880808109b22cd998715c /tests | |
parent | 4b0a5edd47142a02e5bf585d8009195a29036449 (diff) | |
download | oauth2client-6a273d678b23b63845e636c0ed6550ce0c23616a.tar.gz |
Expand API for step2_exchange
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: #443, #446
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_client.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index 03b30fb..684f7bd 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -79,6 +79,7 @@ from oauth2client.client import flow_from_clientsecrets 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)' @@ -1201,6 +1202,26 @@ class OAuth2WebServerFlowTest(unittest2.TestCase): 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): |