From 2a762278bea25e79b0b3dc6b95701538b8a563fb Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 15 Aug 2016 08:59:50 -0700 Subject: [PATCH] TO SQUASH: Make dict a global. --- oauth2client/client.py | 4 ++-- tests/test_client.py | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/oauth2client/client.py b/oauth2client/client.py index 05a5f3a86..3bdbb957d 100644 --- a/oauth2client/client.py +++ b/oauth2client/client.py @@ -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). @@ -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) diff --git a/tests/test_client.py b/tests/test_client.py index dbb83678e..dbe11ebaf 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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): @@ -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} @@ -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) @@ -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'):