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

Commit

Permalink
TO SQUASH: Make dict a global.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Aug 15, 2016
1 parent 4444311 commit 2a76227
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions oauth2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
_GCE_METADATA_URI = 'http://169.254.169.254'
_METADATA_FLAVOR_HEADER = 'metadata-flavor' # lowercase header
_DESIRED_METADATA_FLAVOR = 'Google'
_GCE_HEADERS = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR}

# Expose utcnow() at module level to allow for
# easier testing (by replacing with a stub).
Expand Down Expand Up @@ -1000,10 +1001,9 @@ def _detect_gce_environment():
# the metadata resolution was particularly slow. The latter case is
# "unlikely".
http = transport.get_http_object(timeout=GCE_METADATA_TIMEOUT)
headers = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR}
try:
response, _ = transport.request(
http, _GCE_METADATA_URI, headers=headers)
http, _GCE_METADATA_URI, headers=_GCE_HEADERS)
return (
response.status == http_client.OK and
response.get(_METADATA_FLAVOR_HEADER) == _DESIRED_METADATA_FLAVOR)
Expand Down
9 changes: 3 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@


DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
METADATA_HEADERS = {
client._METADATA_FLAVOR_HEADER: client._DESIRED_METADATA_FLAVOR,
}


def assertUrisEqual(testcase, expected, actual):
Expand Down Expand Up @@ -362,7 +359,7 @@ def _environment_check_gce_helper(self, status_ok=True,
server_software=''):
if status_ok:
headers = {'status': http_client.OK}
headers.update(METADATA_HEADERS)
headers.update(client._GCE_HEADERS)
else:
headers = {'status': http_client.NOT_FOUND}

Expand All @@ -389,7 +386,7 @@ def _environment_check_gce_helper(self, status_ok=True,
self.assertEqual(http.uri, client._GCE_METADATA_URI)
self.assertEqual(http.method, 'GET')
self.assertIsNone(http.body)
self.assertEqual(http.headers, METADATA_HEADERS)
self.assertEqual(http.headers, client._GCE_HEADERS)
else:
new_http.assert_not_called()
self.assertEqual(http.requests, 0)
Expand All @@ -415,7 +412,7 @@ def test_environment_check_gce_timeout(self, mock_request, new_http):
new_http.assert_called_once_with(timeout=client.GCE_METADATA_TIMEOUT)
mock_request.assert_called_once_with(
new_http.return_value, client._GCE_METADATA_URI,
headers=METADATA_HEADERS)
headers=client._GCE_HEADERS)

def test_environ_check_gae_module_unknown(self):
with mock_module_import('google.appengine'):
Expand Down

0 comments on commit 2a76227

Please sign in to comment.