Skip to content

Conversation

@theacodes
Copy link
Contributor

Implementation of the plan detailed over at #15.

@theacodes theacodes added this to the 1.0.0 milestone Oct 12, 2016
@theacodes theacodes force-pushed the urllib3-authorized-http branch from 965389b to 624fa02 Compare October 12, 2016 22:05
from six.moves import http_client

DEFAULT_REFRESH_STATUS_CODES = (http_client.UNAUTHORIZED,)
DEFAULT_MAX_REFRESH_ATTEMPTS = 2

This comment was marked as spam.

This comment was marked as spam.

try:
import certifi
except ImportError: # pragma: NO COVER
certifi = None

This comment was marked as spam.

This comment was marked as spam.

http = urllib3.PoolManager()
request = google.auth.transport.urllib3.Request(http)
credentials.refresh(request)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.



def _make_default_http():
if certifi:

This comment was marked as spam.

This comment was marked as spam.

if certifi:
return urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())

This comment was marked as spam.

This comment was marked as spam.

self.headers = headers or {}

def urlopen(self, method, url, body=None, headers=None, **kwargs):
self.requests.append((method, url, body, headers))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return self.responses.pop(0)


class MockResponse(object):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

mock.sentinel.credentials)

assert authed_http.credentials == mock.sentinel.credentials
assert authed_http.http is not None

This comment was marked as spam.

This comment was marked as spam.

assert authed_http.http is not None

def test_urlopen_no_refresh(self):
mock_credentials = mock.Mock(wraps=MockCredentials())

This comment was marked as spam.

This comment was marked as spam.

def test_urlopen_refresh(self):
mock_credentials = mock.Mock(wraps=MockCredentials())
mock_final_response = MockResponse(status=http_client.OK)
# First request will 403, second request will succeed.

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Oct 13, 2016

@jonparrott We have anything left?

@theacodes
Copy link
Contributor Author

Don't think so.

On Wed, Oct 12, 2016, 10:46 PM Danny Hermes [email protected]
wrote:

@jonparrott https://github.com/jonparrott We have anything left?


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAPUc8mIfZ4OLMoPGnPioce6t7ufaTF7ks5qzcWsgaJpZM4KVNbu
.

@dhermes
Copy link
Contributor

dhermes commented Oct 13, 2016

👍 LGTM then

@theacodes theacodes merged commit 27f6e1e into master Oct 13, 2016
@theacodes theacodes deleted the urllib3-authorized-http branch October 13, 2016 16:46
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.

3 participants