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

Add google.oauth2._client #13

Merged
merged 2 commits into from
Oct 7, 2016
Merged

Add google.oauth2._client #13

merged 2 commits into from
Oct 7, 2016

Conversation

theacodes
Copy link
Contributor

(branch name unrelated)

@theacodes theacodes added this to the 1.0.0 milestone Oct 7, 2016
@theacodes
Copy link
Contributor Author

Context: this will be used by oauth2.0-based credentials:

https://github.com/GoogleCloudPlatform/google-auth-library-python/blob/prototype/google/oauth2/service_account.py#L257

https://github.com/GoogleCloudPlatform/google-auth-library-python/blob/prototype/google/oauth2/credentials.py#L76

Having the grants implemented in one place vastly simplifies the credential implementations and makes it far easy to cover in tests.

error_data['error'],
error_data.get('error_description')])
# If not details could be extracted, use the response data.
except (KeyError, ValueError):

This comment was marked as spam.

This comment was marked as spam.

specified.
"""
expires_in = response_data.get('expires_in', None)
if expires_in:

This comment was marked as spam.

This comment was marked as spam.

return _helpers.utcnow() + datetime.timedelta(
seconds=expires_in)
else:
return None

This comment was marked as spam.

This comment was marked as spam.

"""
body = urllib.parse.urlencode(body)
headers = {
'content-type': 'application/x-www-form-urlencoded',

This comment was marked as spam.

This comment was marked as spam.

response = request(
method='POST', url=token_uri, headers=headers, body=body)

response_body = response.data.decode('utf-8')

This comment was marked as spam.

This comment was marked as spam.


response_data = _token_endpoint_request(request, token_uri, body)

access_token = response_data['access_token']

This comment was marked as spam.

This comment was marked as spam.

import json

import mock
import pytest

This comment was marked as spam.

This comment was marked as spam.

def test__handle_error_response():
response_data = json.dumps({
'error': 'help',
'error_description': 'I\'m alive'})

This comment was marked as spam.

This comment was marked as spam.

with pytest.raises(exceptions.RefreshError) as excinfo:
_client._handle_error_response(response_data)

assert excinfo.match(r'help: I\'m alive')

This comment was marked as spam.

This comment was marked as spam.

assert _client._parse_expiry({}) is None


def test__token_endpoint_request():

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Oct 7, 2016

LGTM

@theacodes theacodes merged commit 123a48b into master Oct 7, 2016
@theacodes theacodes deleted the oauth2client branch October 7, 2016 22:33
@theacodes theacodes mentioned this pull request Oct 21, 2016
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants