Skip to content

Commit

Permalink
Merge pull request #2703 from dhermes/connection-non-public
Browse files Browse the repository at this point in the history
Making base connection module non-public and making connection attribute non-public
  • Loading branch information
dhermes authored Nov 11, 2016
2 parents 92aa585 + 13c917d commit 3414d0f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
4 changes: 2 additions & 2 deletions google-cloud-speech/google/cloud/speech/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from google.cloud._helpers import make_secure_channel
from google.cloud._helpers import make_secure_stub
from google.cloud.connection import DEFAULT_USER_AGENT
from google.cloud._http import DEFAULT_USER_AGENT

from google.cloud.speech.alternative import Alternative
from google.cloud.speech.operation import Operation
Expand All @@ -39,7 +39,7 @@ class GAPICSpeechAPI(object):
"""Manage calls through GAPIC wrappers to the Speech API."""
def __init__(self, client=None):
self._client = client
credentials = self._client.connection.credentials
credentials = self._client._connection.credentials
channel = make_secure_channel(
credentials, DEFAULT_USER_AGENT,
SpeechApi.SERVICE_ADDRESS)
Expand Down
11 changes: 1 addition & 10 deletions google-cloud-speech/google/cloud/speech/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,7 @@ class _JSONSpeechAPI(object):
"""
def __init__(self, client):
self._client = client
self._connection = client.connection

@property
def connection(self):
"""Connection property.
:rtype: :class:`~google.cloud.core.connection.Connection`
:returns: Instance of ``Connection``
"""
return self._connection
self._connection = client._connection

def async_recognize(self, sample, language_code=None,
max_alternatives=None, profanity_filter=None,
Expand Down
4 changes: 2 additions & 2 deletions google-cloud-speech/google/cloud/speech/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

"""Create / interact with Google Cloud Speech 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 Speech JSON REST API."""

API_BASE_URL = 'https://speech.googleapis.com'
Expand Down
44 changes: 22 additions & 22 deletions google-cloud-speech/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def test_ctor(self):
creds = _Credentials()
http = object()
client = self._make_one(credentials=creds, http=http)
self.assertIsInstance(client.connection, Connection)
self.assertTrue(client.connection.credentials is creds)
self.assertTrue(client.connection.http is http)
self.assertIsInstance(client._connection, Connection)
self.assertTrue(client._connection.credentials is creds)
self.assertTrue(client._connection.http is http)

def test_ctor_use_gax_preset(self):
creds = _Credentials()
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
}
credentials = _Credentials()
client = self._make_one(credentials=credentials, use_gax=False)
client.connection = _Connection(RETURNED)
client._connection = _Connection(RETURNED)

encoding = speech.Encoding.FLAC

Expand All @@ -160,8 +160,8 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
profanity_filter=True,
speech_context=self.HINTS)

self.assertEqual(len(client.connection._requested), 1)
req = client.connection._requested[0]
self.assertEqual(len(client._connection._requested), 1)
req = client._connection._requested[0]
self.assertEqual(len(req), 3)
self.assertEqual(req['data'], REQUEST)
self.assertEqual(req['method'], 'POST')
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
}
credentials = _Credentials()
client = self._make_one(credentials=credentials, use_gax=False)
client.connection = _Connection(RETURNED)
client._connection = _Connection(RETURNED)

encoding = speech.Encoding.FLAC

Expand All @@ -201,8 +201,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):

response = client.sync_recognize(sample)

self.assertEqual(len(client.connection._requested), 1)
req = client.connection._requested[0]
self.assertEqual(len(client._connection._requested), 1)
req = client._connection._requested[0]
self.assertEqual(len(req), 3)
self.assertEqual(req['data'], REQUEST)
self.assertEqual(req['method'], 'POST')
Expand All @@ -222,7 +222,7 @@ def test_sync_recognize_with_empty_results_no_gax(self):

credentials = _Credentials()
client = self._make_one(credentials=credentials, use_gax=False)
client.connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)
client._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)

sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
encoding=speech.Encoding.FLAC,
Expand All @@ -240,8 +240,8 @@ def test_sync_recognize_with_empty_results_gax(self):

credentials = _Credentials()
client = self._make_one(credentials=credentials, use_gax=True)
client.connection = _Connection()
client.connection.credentials = credentials
client._connection = _Connection()
client._connection.credentials = credentials

channel_args = []
channel_obj = object()
Expand Down Expand Up @@ -283,8 +283,8 @@ def test_sync_recognize_with_gax(self):

creds = _Credentials()
client = self._make_one(credentials=creds, use_gax=True)
client.connection = _Connection()
client.connection.credentials = creds
client._connection = _Connection()
client._connection.credentials = creds
client._speech_api = None

alternatives = [{
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_async_supported_encodings(self):

credentials = _Credentials()
client = self._make_one(credentials=credentials)
client.connection = _Connection({})
client._connection = _Connection({})

sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
encoding=speech.Encoding.FLAC,
Expand All @@ -362,7 +362,7 @@ def test_async_recognize_no_gax(self):

credentials = _Credentials()
client = self._make_one(credentials=credentials, use_gax=False)
client.connection = _Connection(RETURNED)
client._connection = _Connection(RETURNED)

sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
encoding=speech.Encoding.LINEAR16,
Expand All @@ -385,8 +385,8 @@ def test_async_recognize_with_gax(self):
credentials = _Credentials()
client = self._make_one(credentials=credentials,
use_gax=True)
client.connection = _Connection()
client.connection.credentials = credentials
client._connection = _Connection()
client._connection.credentials = credentials

channel_args = []
channel_obj = object()
Expand Down Expand Up @@ -652,8 +652,8 @@ def test_speech_api_with_gax(self):

creds = _Credentials()
client = self._make_one(credentials=creds, use_gax=True)
client.connection = _Connection()
client.connection.credentials = creds
client._connection = _Connection()
client._connection.credentials = creds

channel_args = []
channel_obj = object()
Expand All @@ -680,14 +680,14 @@ def speech_api(channel=None):
self.assertEqual(channel_args, [expected])

def test_speech_api_without_gax(self):
from google.cloud.connection import Connection
from google.cloud._http import Connection
from google.cloud.speech.client import _JSONSpeechAPI

creds = _Credentials()
client = self._make_one(credentials=creds, use_gax=False)
self.assertIsNone(client._speech_api)
self.assertIsInstance(client.speech_api, _JSONSpeechAPI)
self.assertIsInstance(client.speech_api.connection, Connection)
self.assertIsInstance(client.speech_api._connection, Connection)

def test_speech_api_preset(self):
creds = _Credentials()
Expand Down

0 comments on commit 3414d0f

Please sign in to comment.