Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit 3eb4077

Browse files
committed
TO SQUASH: Make dict a global.
1 parent 625a8d5 commit 3eb4077

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

oauth2client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
_GCE_METADATA_URI = 'http://169.254.169.254'
114114
_METADATA_FLAVOR_HEADER = 'metadata-flavor' # lowercase header
115115
_DESIRED_METADATA_FLAVOR = 'Google'
116+
_GCE_HEADERS = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR}
116117

117118
# Expose utcnow() at module level to allow for
118119
# easier testing (by replacing with a stub).
@@ -1000,10 +1001,9 @@ def _detect_gce_environment():
10001001
# the metadata resolution was particularly slow. The latter case is
10011002
# "unlikely".
10021003
http = transport.get_http_object(timeout=GCE_METADATA_TIMEOUT)
1003-
headers = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR}
10041004
try:
10051005
response, _ = transport.request(
1006-
http, _GCE_METADATA_URI, headers=headers)
1006+
http, _GCE_METADATA_URI, headers=_GCE_HEADERS)
10071007
return (
10081008
response.status == http_client.OK and
10091009
response.get(_METADATA_FLAVOR_HEADER) == _DESIRED_METADATA_FLAVOR)

tests/test_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040

4141

4242
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
43-
METADATA_HEADERS = {
44-
client._METADATA_FLAVOR_HEADER: client._DESIRED_METADATA_FLAVOR,
45-
}
4643

4744

4845
def assertUrisEqual(testcase, expected, actual):
@@ -362,7 +359,7 @@ def _environment_check_gce_helper(self, status_ok=True,
362359
server_software=''):
363360
if status_ok:
364361
headers = {'status': http_client.OK}
365-
headers.update(METADATA_HEADERS)
362+
headers.update(client._GCE_HEADERS)
366363
else:
367364
headers = {'status': http_client.NOT_FOUND}
368365

@@ -389,7 +386,7 @@ def _environment_check_gce_helper(self, status_ok=True,
389386
self.assertEqual(http.uri, client._GCE_METADATA_URI)
390387
self.assertEqual(http.method, 'GET')
391388
self.assertIsNone(http.body)
392-
self.assertEqual(http.headers, METADATA_HEADERS)
389+
self.assertEqual(http.headers, client._GCE_HEADERS)
393390
else:
394391
new_http.assert_not_called()
395392
self.assertEqual(http.requests, 0)
@@ -415,7 +412,7 @@ def test_environment_check_gce_timeout(self, mock_request, new_http):
415412
new_http.assert_called_once_with(timeout=client.GCE_METADATA_TIMEOUT)
416413
mock_request.assert_called_once_with(
417414
new_http.return_value, client._GCE_METADATA_URI,
418-
headers=METADATA_HEADERS)
415+
headers=client._GCE_HEADERS)
419416

420417
def test_environ_check_gae_module_unknown(self):
421418
with mock_module_import('google.appengine'):

0 commit comments

Comments
 (0)