From 0bc8caf30c1549464eb802e90d01e0ab2317a364 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 7 Nov 2016 19:41:24 -0800 Subject: [PATCH] Updating connection -> _connection attribute in some packages. In particular: pubsub/resource_manager/runtimeconfig/speech/translate. --- .../google/cloud/translate/client.py | 8 ++--- .../google/cloud/translate/connection.py | 4 +-- .../unit_tests/test_client.py | 34 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/google-cloud-translate/google/cloud/translate/client.py b/packages/google-cloud-translate/google/cloud/translate/client.py index 572fa2c32e20..f28bd996dffd 100644 --- a/packages/google-cloud-translate/google/cloud/translate/client.py +++ b/packages/google-cloud-translate/google/cloud/translate/client.py @@ -47,7 +47,7 @@ def __init__(self, api_key, http=None, target_language=ENGLISH_ISO_639): self.api_key = api_key if http is None: http = httplib2.Http() - self.connection = Connection(http=http) + self._connection = Connection(http=http) self.target_language = target_language def get_languages(self, target_language=None): @@ -75,7 +75,7 @@ def get_languages(self, target_language=None): target_language = self.target_language if target_language is not None: query_params['target'] = target_language - response = self.connection.api_request( + response = self._connection.api_request( method='GET', path='/languages', query_params=query_params) return response.get('data', {}).get('languages', ()) @@ -117,7 +117,7 @@ def detect_language(self, values): query_params = [('key', self.api_key)] query_params.extend(('q', _to_bytes(value, 'utf-8')) for value in values) - response = self.connection.api_request( + response = self._connection.api_request( method='GET', path='/detect', query_params=query_params) detections = response.get('data', {}).get('detections', ()) @@ -208,7 +208,7 @@ def translate(self, values, target_language=None, format_=None, if source_language is not None: query_params.append(('source', source_language)) - response = self.connection.api_request( + response = self._connection.api_request( method='GET', path='', query_params=query_params) translations = response.get('data', {}).get('translations', ()) diff --git a/packages/google-cloud-translate/google/cloud/translate/connection.py b/packages/google-cloud-translate/google/cloud/translate/connection.py index e1df5a347b91..453a612edfa9 100644 --- a/packages/google-cloud-translate/google/cloud/translate/connection.py +++ b/packages/google-cloud-translate/google/cloud/translate/connection.py @@ -14,10 +14,10 @@ """Create / interact with Google Cloud Translate connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Translate via the JSON REST API.""" API_BASE_URL = 'https://www.googleapis.com' diff --git a/packages/google-cloud-translate/unit_tests/test_client.py b/packages/google-cloud-translate/unit_tests/test_client.py index f28f2b0c16d6..f3a9ffb76871 100644 --- a/packages/google-cloud-translate/unit_tests/test_client.py +++ b/packages/google-cloud-translate/unit_tests/test_client.py @@ -33,9 +33,9 @@ def test_ctor(self): http = object() client = self._make_one(self.KEY, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertIsNone(client.connection.credentials) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIsNone(client._connection.credentials) + self.assertIs(client._connection.http, http) self.assertEqual(client.target_language, ENGLISH_ISO_639) def test_ctor_non_default(self): @@ -44,9 +44,9 @@ def test_ctor_non_default(self): http = object() target = 'es' client = self._make_one(self.KEY, http=http, target_language=target) - self.assertIsInstance(client.connection, Connection) - self.assertIsNone(client.connection.credentials) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIsNone(client._connection.credentials) + self.assertIs(client._connection.http, http) self.assertEqual(client.target_language, target) def test_get_languages(self): @@ -63,7 +63,7 @@ def test_get_languages(self): 'languages': supported, }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.get_languages() self.assertEqual(result, supported) @@ -88,7 +88,7 @@ def test_get_languages_no_target(self): 'languages': supported, }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.get_languages() self.assertEqual(result, supported) @@ -113,7 +113,7 @@ def test_get_languages_explicit_target(self): 'languages': supported, }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.get_languages(target_language) self.assertEqual(result, supported) @@ -129,7 +129,7 @@ def test_get_languages_explicit_target(self): def test_detect_language_bad_result(self): client = self._make_one(self.KEY) value = 'takoy' - conn = client.connection = _Connection({}) + conn = client._connection = _Connection({}) with self.assertRaises(ValueError): client.detect_language(value) @@ -159,7 +159,7 @@ def test_detect_language_single_value(self): 'detections': [[detection]], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.detect_language(value) self.assertEqual(result, detection) @@ -199,7 +199,7 @@ def test_detect_language_multiple_values(self): ], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.detect_language([value1, value2]) self.assertEqual(result, [detection1, detection2]) @@ -236,7 +236,7 @@ def test_detect_language_multiple_results(self): 'detections': [[detection1, detection2]], }, } - client.connection = _Connection(data) + client._connection = _Connection(data) with self.assertRaises(ValueError): client.detect_language(value) @@ -244,7 +244,7 @@ def test_detect_language_multiple_results(self): def test_translate_bad_result(self): client = self._make_one(self.KEY) value = 'hvala ti' - conn = client.connection = _Connection({}) + conn = client._connection = _Connection({}) with self.assertRaises(ValueError): client.translate(value) @@ -274,7 +274,7 @@ def test_translate_defaults(self): 'translations': [translation], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.translate(value) self.assertEqual(result, translation) @@ -310,7 +310,7 @@ def test_translate_multiple(self): 'translations': [translation1, translation2], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.translate([value1, value2]) self.assertEqual(result, [translation1, translation2]) @@ -342,7 +342,7 @@ def test_translate_explicit(self): 'translations': [translation], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) cid = '123' format_ = 'text'