diff --git a/error_reporting/google/cloud/error_reporting/_gax.py b/error_reporting/google/cloud/error_reporting/_gax.py index a5a58995135f..a516572966d1 100644 --- a/error_reporting/google/cloud/error_reporting/_gax.py +++ b/error_reporting/google/cloud/error_reporting/_gax.py @@ -36,7 +36,7 @@ def make_report_error_api(client): :returns: An Error Reporting API instance. """ channel = make_secure_channel( - client._connection.credentials, + client._credentials, DEFAULT_USER_AGENT, report_errors_service_client.ReportErrorsServiceClient.SERVICE_ADDRESS) gax_client = report_errors_service_client.ReportErrorsServiceClient( diff --git a/error_reporting/unit_tests/test__gax.py b/error_reporting/unit_tests/test__gax.py index b5345045ca8b..277d57b8f5db 100644 --- a/error_reporting/unit_tests/test__gax.py +++ b/error_reporting/unit_tests/test__gax.py @@ -28,7 +28,11 @@ def test_make_report_error_api(self): from google.cloud.error_reporting import __version__ from google.cloud.error_reporting._gax import make_report_error_api - client = mock.Mock() + client = mock.Mock( + _credentials=mock.sentinel.credentials, + project='prahj-ekt', + spec=['project', '_credentials'], + ) # Mock out the constructor for the GAPIC client. ServiceClient = report_errors_service_client.ReportErrorsServiceClient diff --git a/logging/google/cloud/logging/_gax.py b/logging/google/cloud/logging/_gax.py index b9eea35bd0fb..cd8cccbd3eaa 100644 --- a/logging/google/cloud/logging/_gax.py +++ b/logging/google/cloud/logging/_gax.py @@ -533,7 +533,7 @@ def make_gax_logging_api(client): :returns: A metrics API instance with the proper credentials. """ channel = make_secure_channel( - client._connection.credentials, DEFAULT_USER_AGENT, + client._credentials, DEFAULT_USER_AGENT, LoggingServiceV2Client.SERVICE_ADDRESS) generated = LoggingServiceV2Client( channel=channel, lib_name='gccl', lib_version=__version__) @@ -550,7 +550,7 @@ def make_gax_metrics_api(client): :returns: A metrics API instance with the proper credentials. """ channel = make_secure_channel( - client._connection.credentials, DEFAULT_USER_AGENT, + client._credentials, DEFAULT_USER_AGENT, MetricsServiceV2Client.SERVICE_ADDRESS) generated = MetricsServiceV2Client( channel=channel, lib_name='gccl', lib_version=__version__) @@ -567,7 +567,7 @@ def make_gax_sinks_api(client): :returns: A metrics API instance with the proper credentials. """ channel = make_secure_channel( - client._connection.credentials, DEFAULT_USER_AGENT, + client._credentials, DEFAULT_USER_AGENT, ConfigServiceV2Client.SERVICE_ADDRESS) generated = ConfigServiceV2Client( channel=channel, lib_name='gccl', lib_version=__version__) diff --git a/logging/google/cloud/logging/handlers/transports/background_thread.py b/logging/google/cloud/logging/handlers/transports/background_thread.py index 811bc23bdb9f..9c8ea85c937a 100644 --- a/logging/google/cloud/logging/handlers/transports/background_thread.py +++ b/logging/google/cloud/logging/handlers/transports/background_thread.py @@ -152,7 +152,7 @@ class BackgroundThreadTransport(Transport): def __init__(self, client, name): http = copy.deepcopy(client._http) self.client = client.__class__( - client.project, client._connection.credentials, http) + client.project, client._credentials, http) logger = self.client.logger(name) self.worker = _Worker(logger) diff --git a/logging/unit_tests/test__gax.py b/logging/unit_tests/test__gax.py index 3f3973152206..1a69586651e9 100644 --- a/logging/unit_tests/test__gax.py +++ b/logging/unit_tests/test__gax.py @@ -1113,8 +1113,7 @@ def test_it(self): from google.cloud.logging._gax import DEFAULT_USER_AGENT creds = object() - conn = mock.Mock(credentials=creds, spec=['credentials']) - client = mock.Mock(_connection=conn, spec=['_connection']) + client = mock.Mock(_credentials=creds, spec=['_credentials']) channels = [] channel_args = [] generated_api_kwargs = [] @@ -1167,8 +1166,7 @@ def test_it(self): from google.cloud.logging._gax import DEFAULT_USER_AGENT creds = object() - conn = mock.Mock(credentials=creds, spec=['credentials']) - client = mock.Mock(_connection=conn, spec=['_connection']) + client = mock.Mock(_credentials=creds, spec=['_credentials']) channels = [] channel_args = [] generated_api_kwargs = [] @@ -1221,8 +1219,7 @@ def test_it(self): from google.cloud.logging._gax import DEFAULT_USER_AGENT creds = object() - conn = mock.Mock(credentials=creds, spec=['credentials']) - client = mock.Mock(_connection=conn, spec=['_connection']) + client = mock.Mock(_credentials=creds, spec=['_credentials']) channels = [] channel_args = [] generated_api_kwargs = [] diff --git a/speech/google/cloud/speech/_gax.py b/speech/google/cloud/speech/_gax.py index 331b80059a0e..963420f54028 100644 --- a/speech/google/cloud/speech/_gax.py +++ b/speech/google/cloud/speech/_gax.py @@ -42,7 +42,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._credentials channel = make_secure_channel( credentials, DEFAULT_USER_AGENT, SpeechClient.SERVICE_ADDRESS) diff --git a/speech/google/cloud/speech/_http.py b/speech/google/cloud/speech/_http.py index 3b82a25802ef..870bf62edc67 100644 --- a/speech/google/cloud/speech/_http.py +++ b/speech/google/cloud/speech/_http.py @@ -57,7 +57,7 @@ class HTTPSpeechAPI(object): """ def __init__(self, client): self._client = client - self._connection = client._connection + self._connection = Connection(client) def async_recognize(self, sample, language_code=None, max_alternatives=None, profanity_filter=None, diff --git a/speech/google/cloud/speech/client.py b/speech/google/cloud/speech/client.py index f534ab63d1b4..c48a4d66dde1 100644 --- a/speech/google/cloud/speech/client.py +++ b/speech/google/cloud/speech/client.py @@ -20,7 +20,6 @@ from google.cloud.environment_vars import DISABLE_GRPC from google.cloud.speech._gax import GAPICSpeechAPI -from google.cloud.speech._http import Connection from google.cloud.speech._http import HTTPSpeechAPI from google.cloud.speech.sample import Sample @@ -58,8 +57,6 @@ class Client(BaseClient): def __init__(self, credentials=None, http=None, use_gax=None): super(Client, self).__init__(credentials=credentials, http=http) - self._connection = Connection(self) - # Save on the actual client class whether we use GAX or not. if use_gax is None: self._use_gax = _USE_GAX diff --git a/speech/unit_tests/test__gax.py b/speech/unit_tests/test__gax.py index c67d6defbbe9..8c7efea77bb1 100644 --- a/speech/unit_tests/test__gax.py +++ b/speech/unit_tests/test__gax.py @@ -49,11 +49,16 @@ def test_constructor(self, mocked_stub, mocked_cls, mocked_channel): from google.cloud.speech import __version__ from google.cloud.speech._gax import OPERATIONS_API_HOST + credentials = _make_credentials() mock_cnxn = mock.Mock( - credentials=_make_credentials(), + credentials=credentials, spec=['credentials'], ) - mock_client = mock.Mock(_connection=mock_cnxn, spec=['_connection']) + mock_client = mock.Mock( + _connection=mock_cnxn, + _credentials=credentials, + spec=['_connection', '_credentials'], + ) speech_api = self._make_one(mock_client) self.assertIs(speech_api._client, mock_client) diff --git a/speech/unit_tests/test_client.py b/speech/unit_tests/test_client.py index dc9e762253fd..18e4ec24a88d 100644 --- a/speech/unit_tests/test_client.py +++ b/speech/unit_tests/test_client.py @@ -85,14 +85,11 @@ def _make_one(self, *args, **kw): return self._get_target_class()(*args, **kw) def test_ctor(self): - from google.cloud.speech._http import Connection - creds = _make_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.assertTrue(client._credentials is creds) + self.assertTrue(client._http is http) def test_ctor_use_gax_preset(self): creds = _make_credentials() @@ -153,7 +150,9 @@ def test_sync_recognize_content_with_optional_params_no_gax(self): } credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + speech_api = client.speech_api + connection = _Connection(RETURNED) + speech_api._connection = connection encoding = speech.Encoding.FLAC @@ -165,8 +164,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(connection._requested), 1) + req = connection._requested[0] self.assertEqual(len(req), 3) self.assertEqual(req['data'], REQUEST) self.assertEqual(req['method'], 'POST') @@ -199,7 +198,9 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self): } credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + speech_api = client.speech_api + connection = _Connection(RETURNED) + speech_api._connection = connection encoding = speech.Encoding.FLAC @@ -208,8 +209,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self): response = [i for i in sample.sync_recognize()] - self.assertEqual(len(client._connection._requested), 1) - req = client._connection._requested[0] + self.assertEqual(len(connection._requested), 1) + req = connection._requested[0] self.assertEqual(len(req), 3) self.assertEqual(req['data'], REQUEST) self.assertEqual(req['method'], 'POST') @@ -231,7 +232,8 @@ def test_sync_recognize_with_empty_results_no_gax(self): credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=False) - client._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE) + speech_api = client.speech_api + speech_api._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE) sample = client.sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.FLAC, @@ -248,8 +250,7 @@ def test_sync_recognize_with_empty_results_gax(self): credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=True) - client._connection = _Connection() - client._connection.credentials = credentials + client._credentials = credentials channel_args = [] channel_obj = object() @@ -291,9 +292,7 @@ def test_sync_recognize_with_gax(self): creds = _make_credentials() client = self._make_one(credentials=creds, use_gax=True) - client._connection = _Connection() - client._connection.credentials = creds - client._speech_api = None + client._credentials = creds alternatives = [{ 'transcript': 'testing 1 2 3', @@ -352,8 +351,7 @@ def test_async_supported_encodings(self): from google.cloud import speech credentials = _make_credentials() - client = self._make_one(credentials=credentials) - client._connection = _Connection({}) + client = self._make_one(credentials=credentials, use_gax=True) sample = client.sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.FLAC, @@ -370,7 +368,8 @@ def test_async_recognize_no_gax(self): credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + speech_api = client.speech_api + speech_api._connection = _Connection(RETURNED) sample = client.sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.LINEAR16, @@ -393,8 +392,7 @@ def test_async_recognize_with_gax(self): credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=True) - client._connection = _Connection() - client._connection.credentials = credentials + client._credentials = credentials channel_args = [] channel_obj = object() @@ -434,7 +432,6 @@ def test_streaming_depends_on_gax(self): credentials = _make_credentials() client = self._make_one(credentials=credentials, use_gax=False) - client.connection = _Connection() sample = client.sample(content=self.AUDIO_CONTENT, encoding=speech.Encoding.LINEAR16, sample_rate=self.SAMPLE_RATE) @@ -453,8 +450,7 @@ def test_streaming_closed_stream(self): stream = BytesIO(b'Some audio data...') credentials = _make_credentials() client = self._make_one(credentials=credentials) - client.connection = _Connection() - client.connection.credentials = credentials + client._credentials = credentials channel_args = [] channel_obj = object() @@ -495,8 +491,7 @@ def test_stream_recognize_interim_results(self): stream = BytesIO(b'Some audio data...') credentials = _make_credentials() client = self._make_one(credentials=credentials) - client.connection = _Connection() - client.connection.credentials = credentials + client._credentials = credentials alternatives = [{ 'transcript': 'testing streaming 1 2 3', @@ -576,8 +571,7 @@ def test_stream_recognize(self): stream = BytesIO(b'Some audio data...') credentials = _make_credentials() client = self._make_one(credentials=credentials) - client.connection = _Connection() - client.connection.credentials = credentials + client._credentials = credentials alternatives = [{ 'transcript': 'testing streaming 1 2 3', @@ -633,8 +627,7 @@ def test_stream_recognize_no_results(self): stream = BytesIO(b'Some audio data...') credentials = _make_credentials() client = self._make_one(credentials=credentials) - client.connection = _Connection() - client.connection.credentials = credentials + client._credentials = credentials responses = [_make_streaming_response()] @@ -670,8 +663,7 @@ def test_speech_api_with_gax(self): creds = _make_credentials() client = self._make_one(credentials=creds, use_gax=True) - client._connection = _Connection() - client._connection.credentials = creds + client._credentials = creds channel_args = [] channel_obj = object() diff --git a/vision/google/cloud/vision/_http.py b/vision/google/cloud/vision/_http.py index cd024e7ba3dd..7ce94e218a3a 100644 --- a/vision/google/cloud/vision/_http.py +++ b/vision/google/cloud/vision/_http.py @@ -55,7 +55,7 @@ class _HTTPVisionAPI(object): def __init__(self, client): self._client = client - self._connection = client._connection + self._connection = Connection(client) def annotate(self, images): """Annotate an image to discover it's attributes. diff --git a/vision/google/cloud/vision/client.py b/vision/google/cloud/vision/client.py index 99a7664953ee..c102fd16ecc7 100644 --- a/vision/google/cloud/vision/client.py +++ b/vision/google/cloud/vision/client.py @@ -21,7 +21,6 @@ from google.cloud.vision._gax import _GAPICVisionAPI from google.cloud.vision._http import _HTTPVisionAPI -from google.cloud.vision._http import Connection from google.cloud.vision.batch import Batch from google.cloud.vision.image import Image @@ -66,7 +65,6 @@ def __init__(self, project=None, credentials=None, http=None, use_gax=None): super(Client, self).__init__( project=project, credentials=credentials, http=http) - self._connection = Connection(self) if use_gax is None: self._use_gax = _USE_GAX else: diff --git a/vision/unit_tests/test_client.py b/vision/unit_tests/test_client.py index e1f23f6d4be9..7b87f0e6fc80 100644 --- a/vision/unit_tests/test_client.py +++ b/vision/unit_tests/test_client.py @@ -47,7 +47,8 @@ def test_ctor(self): def test_annotate_with_preset_api(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client._connection = _Connection() + vision_api = client._vision_api + vision_api._connection = _Connection() api = mock.Mock() api.annotate.return_value = mock.sentinel.annotated @@ -62,7 +63,8 @@ def test_make_gax_client(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=None) - client._connection = _Connection() + vision_api = client._vision_api + vision_api._connection = _Connection() with mock.patch('google.cloud.vision.client._GAPICVisionAPI', spec=True): self.assertIsInstance(client._vision_api, _GAPICVisionAPI) @@ -73,7 +75,8 @@ def test_make_http_client(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection() + vision_api = client._vision_api + vision_api._connection = _Connection() self.assertIsInstance(client._vision_api, _HTTPVisionAPI) def test_face_annotation(self): @@ -100,7 +103,9 @@ def test_face_annotation(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection features = [Feature(feature_type=FeatureTypes.FACE_DETECTION, max_results=3)] @@ -110,8 +115,8 @@ def test_face_annotation(self): self.assertEqual(len(api_response), 1) response = api_response[0] - self.assertEqual(REQUEST, - client._connection._requested[0]['data']) + self.assertEqual( + REQUEST, connection._requested[0]['data']) self.assertIsInstance(response, Annotations) def test_image_with_client_gcs_source(self): @@ -163,7 +168,9 @@ def test_multiple_detection_from_content(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(returned) + vision_api = client._vision_api + connection = _Connection(returned) + vision_api._connection = connection limit = 2 label_feature = Feature(FeatureTypes.LABEL_DETECTION, limit) @@ -193,7 +200,7 @@ def test_multiple_detection_from_content(self): self.assertEqual(third_label.description, 'truck') self.assertEqual(third_label.score, 0.88429511) - requested = client._connection._requested + requested = connection._requested requests = requested[0]['data']['requests'] image_request = requests[0] label_request = image_request['features'][0] @@ -213,13 +220,15 @@ def test_face_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) faces = image.detect_faces(limit=3) self.assertEqual(5, len(faces)) self.assertIsInstance(faces[0], Face) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -231,13 +240,15 @@ def test_face_detection_from_content(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(content=IMAGE_CONTENT) faces = image.detect_faces(limit=5) self.assertEqual(5, len(faces)) self.assertIsInstance(faces[0], Face) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) @@ -250,13 +261,15 @@ def test_face_detection_from_content_no_results(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(content=IMAGE_CONTENT) faces = image.detect_faces(limit=5) self.assertEqual(faces, ()) self.assertEqual(len(faces), 0) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) @@ -270,13 +283,15 @@ def test_label_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) labels = image.detect_labels(limit=3) self.assertEqual(3, len(labels)) self.assertIsInstance(labels[0], EntityAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -292,7 +307,8 @@ def test_label_detection_no_results(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + vision_api._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) labels = image.detect_labels() @@ -307,13 +323,15 @@ def test_landmark_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) landmarks = image.detect_landmarks(limit=3) self.assertEqual(2, len(landmarks)) self.assertIsInstance(landmarks[0], EntityAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -330,13 +348,15 @@ def test_landmark_detection_from_content(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(content=IMAGE_CONTENT) landmarks = image.detect_landmarks(limit=5) self.assertEqual(2, len(landmarks)) self.assertIsInstance(landmarks[0], EntityAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) self.assertEqual(5, image_request['features'][0]['maxResults']) @@ -348,7 +368,8 @@ def test_landmark_detection_no_results(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + vision_api._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) landmarks = image.detect_landmarks() @@ -362,13 +383,15 @@ def test_logo_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) logos = image.detect_logos(limit=3) self.assertEqual(2, len(logos)) self.assertIsInstance(logos[0], EntityAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -380,13 +403,15 @@ def test_logo_detection_from_content(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(content=IMAGE_CONTENT) logos = image.detect_logos(limit=5) self.assertEqual(2, len(logos)) self.assertIsInstance(logos[0], EntityAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) self.assertEqual(5, image_request['features'][0]['maxResults']) @@ -399,13 +424,15 @@ def test_text_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) text = image.detect_text(limit=3) self.assertEqual(3, len(text)) self.assertIsInstance(text[0], EntityAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -423,12 +450,14 @@ def test_safe_search_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) safe_search = image.detect_safe_search() self.assertIsInstance(safe_search, SafeSearchAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) @@ -444,7 +473,8 @@ def test_safe_search_no_results(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + vision_api._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) safe_search = image.detect_safe_search() @@ -459,12 +489,14 @@ def test_image_properties_detection_from_source(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + connection = _Connection(RETURNED) + vision_api._connection = connection image = client.image(source_uri=IMAGE_SOURCE) image_properties = image.detect_properties() self.assertIsInstance(image_properties, ImagePropertiesAnnotation) - image_request = client._connection._requested[0]['data']['requests'][0] + image_request = connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(0.42258179, image_properties.colors[0].score) @@ -482,7 +514,8 @@ def test_image_properties_no_results(self): credentials = _make_credentials() client = self._make_one(project=PROJECT, credentials=credentials, use_gax=False) - client._connection = _Connection(RETURNED) + vision_api = client._vision_api + vision_api._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) image_properties = image.detect_properties()