From daa59cd5dacd65669057744368d55e68bd84acdd Mon Sep 17 00:00:00 2001 From: Sai Cheemalapati Date: Thu, 18 May 2017 10:20:51 -0700 Subject: [PATCH] Specify HTTP client when constructing client (#1275) If a HTTP client is not passed to `build`, the Google API Python client will create a default one and attempt to authenticate it. This causes failures in environments where ADC auth is not available (Travis). In any case, it's not useful to access any auth code in the mock tests. This commit removes that possibility. --- .../transformer/py/PythonSampleMethodToViewTransformer.java | 1 + src/main/resources/com/google/api/codegen/py/sample.snip | 3 +++ .../codegen/testdata/discoveries/py/py_foo.v1.json.baseline | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/api/codegen/discovery/transformer/py/PythonSampleMethodToViewTransformer.java b/src/main/java/com/google/api/codegen/discovery/transformer/py/PythonSampleMethodToViewTransformer.java index f0602ce576..6ee04d17bb 100644 --- a/src/main/java/com/google/api/codegen/discovery/transformer/py/PythonSampleMethodToViewTransformer.java +++ b/src/main/java/com/google/api/codegen/discovery/transformer/py/PythonSampleMethodToViewTransformer.java @@ -117,6 +117,7 @@ private SampleView createSampleView(SampleTransformerContext context) { discoveryBuildParams.add(String.format("'%s'", config.apiVersion())); switch (config.authType()) { case NONE: + discoveryBuildParams.add("http=httplib2.Http(timeout=60)"); break; case API_KEY: discoveryBuildParams.add("developerKey=" + credentialsVarName); diff --git a/src/main/resources/com/google/api/codegen/py/sample.snip b/src/main/resources/com/google/api/codegen/py/sample.snip index bf52ff6818..5957449389 100644 --- a/src/main/resources/com/google/api/codegen/py/sample.snip +++ b/src/main/resources/com/google/api/codegen/py/sample.snip @@ -24,6 +24,9 @@ from pprint import pprint @end + @if class.auth.type == "NONE" + import httplib2 + @end from googleapiclient import discovery @if class.auth.type == "APPLICATION_DEFAULT_CREDENTIALS" from oauth2client.client import GoogleCredentials diff --git a/src/test/java/com/google/api/codegen/testdata/discoveries/py/py_foo.v1.json.baseline b/src/test/java/com/google/api/codegen/testdata/discoveries/py/py_foo.v1.json.baseline index e4f28fe1fb..6d6855a4e7 100644 --- a/src/test/java/com/google/api/codegen/testdata/discoveries/py/py_foo.v1.json.baseline +++ b/src/test/java/com/google/api/codegen/testdata/discoveries/py/py_foo.v1.json.baseline @@ -10,9 +10,10 @@ BEFORE RUNNING: """ from pprint import pprint +import httplib2 from googleapiclient import discovery -service = discovery.build('foo', 'v1', discoveryServiceUrl='localhost:8080/$discovery/foo?version=v1') +service = discovery.build('foo', 'v1', http=httplib2.Http(timeout=60), discoveryServiceUrl='localhost:8080/$discovery/foo?version=v1') request = service.baz().get() response = request.execute()