diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index 6291f34e85a..dcb3ee6f4fa 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -708,7 +708,7 @@ def createMethod(methodName, methodDesc, rootDesc, schema): parameters = ResourceMethodParameters(methodDesc) - def method(self, **kwargs): + def method(self, user_agent=None, **kwargs): # Don't bother with doc string, it will be over-written by createMethod. for name in six.iterkeys(kwargs): @@ -780,6 +780,8 @@ def method(self, **kwargs): model = RawModel() headers = {} + if user_agent is not None: + headers['user-agent'] = user_agent headers, params, query, body = model.request(headers, actual_path_params, actual_query_params, body_value) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 47adeb7949a..f5dfbb9ffbc 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -302,6 +302,14 @@ def test_urljoin(self): self.assertEqual(final_url, _urljoin(base, url)) + def test_user_agent_headers(self): + self.http = HttpMock(datafile('zoo.json'), {'status': '200'}) + zoo = build('zoo', 'v1', http=self.http) + + request = zoo.animals().insert(body={}, user_agent='zookeeper') + self.assertTrue(request.headers['user-agent'].startswith('zookeeper')) + + def test_ResourceMethodParameters_zoo_get(self): parameters = ResourceMethodParameters(self.zoo_get_method_desc) @@ -934,7 +942,6 @@ def test_resumable_multipart_media_good_upload(self): self.assertEquals(request.resumable_uri, 'http://upload.example.com/2') self.assertEquals(media_upload, request.resumable) self.assertEquals(0, request.resumable_progress) - # This next chuck call should upload the first chunk status, body = request.next_chunk(http=http) self.assertEquals(request.resumable_uri, 'http://upload.example.com/3')