@@ -47,7 +47,8 @@ def test_ctor(self):
4747 def test_annotate_with_preset_api (self ):
4848 credentials = _make_credentials ()
4949 client = self ._make_one (project = PROJECT , credentials = credentials )
50- client ._connection = _Connection ()
50+ vision_api = client ._vision_api
51+ vision_api ._connection = _Connection ()
5152
5253 api = mock .Mock ()
5354 api .annotate .return_value = mock .sentinel .annotated
@@ -62,7 +63,8 @@ def test_make_gax_client(self):
6263 credentials = _make_credentials ()
6364 client = self ._make_one (project = PROJECT , credentials = credentials ,
6465 use_gax = None )
65- client ._connection = _Connection ()
66+ vision_api = client ._vision_api
67+ vision_api ._connection = _Connection ()
6668 with mock .patch ('google.cloud.vision.client._GAPICVisionAPI' ,
6769 spec = True ):
6870 self .assertIsInstance (client ._vision_api , _GAPICVisionAPI )
@@ -73,7 +75,8 @@ def test_make_http_client(self):
7375 credentials = _make_credentials ()
7476 client = self ._make_one (project = PROJECT , credentials = credentials ,
7577 use_gax = False )
76- client ._connection = _Connection ()
78+ vision_api = client ._vision_api
79+ vision_api ._connection = _Connection ()
7780 self .assertIsInstance (client ._vision_api , _HTTPVisionAPI )
7881
7982 def test_face_annotation (self ):
@@ -100,7 +103,9 @@ def test_face_annotation(self):
100103 credentials = _make_credentials ()
101104 client = self ._make_one (project = PROJECT , credentials = credentials ,
102105 use_gax = False )
103- client ._connection = _Connection (RETURNED )
106+ vision_api = client ._vision_api
107+ connection = _Connection (RETURNED )
108+ vision_api ._connection = connection
104109
105110 features = [Feature (feature_type = FeatureTypes .FACE_DETECTION ,
106111 max_results = 3 )]
@@ -110,8 +115,8 @@ def test_face_annotation(self):
110115
111116 self .assertEqual (len (api_response ), 1 )
112117 response = api_response [0 ]
113- self .assertEqual (REQUEST ,
114- client . _connection ._requested [0 ]['data' ])
118+ self .assertEqual (
119+ REQUEST , connection ._requested [0 ]['data' ])
115120 self .assertIsInstance (response , Annotations )
116121
117122 def test_image_with_client_gcs_source (self ):
@@ -163,7 +168,9 @@ def test_multiple_detection_from_content(self):
163168 credentials = _make_credentials ()
164169 client = self ._make_one (project = PROJECT , credentials = credentials ,
165170 use_gax = False )
166- client ._connection = _Connection (returned )
171+ vision_api = client ._vision_api
172+ connection = _Connection (returned )
173+ vision_api ._connection = connection
167174
168175 limit = 2
169176 label_feature = Feature (FeatureTypes .LABEL_DETECTION , limit )
@@ -193,7 +200,7 @@ def test_multiple_detection_from_content(self):
193200 self .assertEqual (third_label .description , 'truck' )
194201 self .assertEqual (third_label .score , 0.88429511 )
195202
196- requested = client . _connection ._requested
203+ requested = connection ._requested
197204 requests = requested [0 ]['data' ]['requests' ]
198205 image_request = requests [0 ]
199206 label_request = image_request ['features' ][0 ]
@@ -213,13 +220,15 @@ def test_face_detection_from_source(self):
213220 credentials = _make_credentials ()
214221 client = self ._make_one (project = PROJECT , credentials = credentials ,
215222 use_gax = False )
216- client ._connection = _Connection (RETURNED )
223+ vision_api = client ._vision_api
224+ connection = _Connection (RETURNED )
225+ vision_api ._connection = connection
217226
218227 image = client .image (source_uri = IMAGE_SOURCE )
219228 faces = image .detect_faces (limit = 3 )
220229 self .assertEqual (5 , len (faces ))
221230 self .assertIsInstance (faces [0 ], Face )
222- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
231+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
223232 self .assertEqual (IMAGE_SOURCE ,
224233 image_request ['image' ]['source' ]['gcs_image_uri' ])
225234 self .assertEqual (3 , image_request ['features' ][0 ]['maxResults' ])
@@ -231,13 +240,15 @@ def test_face_detection_from_content(self):
231240 credentials = _make_credentials ()
232241 client = self ._make_one (project = PROJECT , credentials = credentials ,
233242 use_gax = False )
234- client ._connection = _Connection (RETURNED )
243+ vision_api = client ._vision_api
244+ connection = _Connection (RETURNED )
245+ vision_api ._connection = connection
235246
236247 image = client .image (content = IMAGE_CONTENT )
237248 faces = image .detect_faces (limit = 5 )
238249 self .assertEqual (5 , len (faces ))
239250 self .assertIsInstance (faces [0 ], Face )
240- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
251+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
241252
242253 self .assertEqual (B64_IMAGE_CONTENT ,
243254 image_request ['image' ]['content' ])
@@ -250,13 +261,15 @@ def test_face_detection_from_content_no_results(self):
250261 credentials = _make_credentials ()
251262 client = self ._make_one (project = PROJECT , credentials = credentials ,
252263 use_gax = False )
253- client ._connection = _Connection (RETURNED )
264+ vision_api = client ._vision_api
265+ connection = _Connection (RETURNED )
266+ vision_api ._connection = connection
254267
255268 image = client .image (content = IMAGE_CONTENT )
256269 faces = image .detect_faces (limit = 5 )
257270 self .assertEqual (faces , ())
258271 self .assertEqual (len (faces ), 0 )
259- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
272+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
260273
261274 self .assertEqual (B64_IMAGE_CONTENT ,
262275 image_request ['image' ]['content' ])
@@ -270,13 +283,15 @@ def test_label_detection_from_source(self):
270283 credentials = _make_credentials ()
271284 client = self ._make_one (project = PROJECT , credentials = credentials ,
272285 use_gax = False )
273- client ._connection = _Connection (RETURNED )
286+ vision_api = client ._vision_api
287+ connection = _Connection (RETURNED )
288+ vision_api ._connection = connection
274289
275290 image = client .image (source_uri = IMAGE_SOURCE )
276291 labels = image .detect_labels (limit = 3 )
277292 self .assertEqual (3 , len (labels ))
278293 self .assertIsInstance (labels [0 ], EntityAnnotation )
279- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
294+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
280295 self .assertEqual (IMAGE_SOURCE ,
281296 image_request ['image' ]['source' ]['gcs_image_uri' ])
282297 self .assertEqual (3 , image_request ['features' ][0 ]['maxResults' ])
@@ -292,7 +307,8 @@ def test_label_detection_no_results(self):
292307 credentials = _make_credentials ()
293308 client = self ._make_one (project = PROJECT , credentials = credentials ,
294309 use_gax = False )
295- client ._connection = _Connection (RETURNED )
310+ vision_api = client ._vision_api
311+ vision_api ._connection = _Connection (RETURNED )
296312
297313 image = client .image (content = IMAGE_CONTENT )
298314 labels = image .detect_labels ()
@@ -307,13 +323,15 @@ def test_landmark_detection_from_source(self):
307323 credentials = _make_credentials ()
308324 client = self ._make_one (project = PROJECT , credentials = credentials ,
309325 use_gax = False )
310- client ._connection = _Connection (RETURNED )
326+ vision_api = client ._vision_api
327+ connection = _Connection (RETURNED )
328+ vision_api ._connection = connection
311329
312330 image = client .image (source_uri = IMAGE_SOURCE )
313331 landmarks = image .detect_landmarks (limit = 3 )
314332 self .assertEqual (2 , len (landmarks ))
315333 self .assertIsInstance (landmarks [0 ], EntityAnnotation )
316- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
334+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
317335 self .assertEqual (IMAGE_SOURCE ,
318336 image_request ['image' ]['source' ]['gcs_image_uri' ])
319337 self .assertEqual (3 , image_request ['features' ][0 ]['maxResults' ])
@@ -330,13 +348,15 @@ def test_landmark_detection_from_content(self):
330348 credentials = _make_credentials ()
331349 client = self ._make_one (project = PROJECT , credentials = credentials ,
332350 use_gax = False )
333- client ._connection = _Connection (RETURNED )
351+ vision_api = client ._vision_api
352+ connection = _Connection (RETURNED )
353+ vision_api ._connection = connection
334354
335355 image = client .image (content = IMAGE_CONTENT )
336356 landmarks = image .detect_landmarks (limit = 5 )
337357 self .assertEqual (2 , len (landmarks ))
338358 self .assertIsInstance (landmarks [0 ], EntityAnnotation )
339- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
359+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
340360 self .assertEqual (B64_IMAGE_CONTENT ,
341361 image_request ['image' ]['content' ])
342362 self .assertEqual (5 , image_request ['features' ][0 ]['maxResults' ])
@@ -348,7 +368,8 @@ def test_landmark_detection_no_results(self):
348368 credentials = _make_credentials ()
349369 client = self ._make_one (project = PROJECT , credentials = credentials ,
350370 use_gax = False )
351- client ._connection = _Connection (RETURNED )
371+ vision_api = client ._vision_api
372+ vision_api ._connection = _Connection (RETURNED )
352373
353374 image = client .image (content = IMAGE_CONTENT )
354375 landmarks = image .detect_landmarks ()
@@ -362,13 +383,15 @@ def test_logo_detection_from_source(self):
362383 credentials = _make_credentials ()
363384 client = self ._make_one (project = PROJECT , credentials = credentials ,
364385 use_gax = False )
365- client ._connection = _Connection (RETURNED )
386+ vision_api = client ._vision_api
387+ connection = _Connection (RETURNED )
388+ vision_api ._connection = connection
366389
367390 image = client .image (source_uri = IMAGE_SOURCE )
368391 logos = image .detect_logos (limit = 3 )
369392 self .assertEqual (2 , len (logos ))
370393 self .assertIsInstance (logos [0 ], EntityAnnotation )
371- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
394+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
372395 self .assertEqual (IMAGE_SOURCE ,
373396 image_request ['image' ]['source' ]['gcs_image_uri' ])
374397 self .assertEqual (3 , image_request ['features' ][0 ]['maxResults' ])
@@ -380,13 +403,15 @@ def test_logo_detection_from_content(self):
380403 credentials = _make_credentials ()
381404 client = self ._make_one (project = PROJECT , credentials = credentials ,
382405 use_gax = False )
383- client ._connection = _Connection (RETURNED )
406+ vision_api = client ._vision_api
407+ connection = _Connection (RETURNED )
408+ vision_api ._connection = connection
384409
385410 image = client .image (content = IMAGE_CONTENT )
386411 logos = image .detect_logos (limit = 5 )
387412 self .assertEqual (2 , len (logos ))
388413 self .assertIsInstance (logos [0 ], EntityAnnotation )
389- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
414+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
390415 self .assertEqual (B64_IMAGE_CONTENT ,
391416 image_request ['image' ]['content' ])
392417 self .assertEqual (5 , image_request ['features' ][0 ]['maxResults' ])
@@ -399,13 +424,15 @@ def test_text_detection_from_source(self):
399424 credentials = _make_credentials ()
400425 client = self ._make_one (project = PROJECT , credentials = credentials ,
401426 use_gax = False )
402- client ._connection = _Connection (RETURNED )
427+ vision_api = client ._vision_api
428+ connection = _Connection (RETURNED )
429+ vision_api ._connection = connection
403430
404431 image = client .image (source_uri = IMAGE_SOURCE )
405432 text = image .detect_text (limit = 3 )
406433 self .assertEqual (3 , len (text ))
407434 self .assertIsInstance (text [0 ], EntityAnnotation )
408- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
435+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
409436 self .assertEqual (IMAGE_SOURCE ,
410437 image_request ['image' ]['source' ]['gcs_image_uri' ])
411438 self .assertEqual (3 , image_request ['features' ][0 ]['maxResults' ])
@@ -423,12 +450,14 @@ def test_safe_search_detection_from_source(self):
423450 credentials = _make_credentials ()
424451 client = self ._make_one (project = PROJECT , credentials = credentials ,
425452 use_gax = False )
426- client ._connection = _Connection (RETURNED )
453+ vision_api = client ._vision_api
454+ connection = _Connection (RETURNED )
455+ vision_api ._connection = connection
427456
428457 image = client .image (source_uri = IMAGE_SOURCE )
429458 safe_search = image .detect_safe_search ()
430459 self .assertIsInstance (safe_search , SafeSearchAnnotation )
431- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
460+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
432461 self .assertEqual (IMAGE_SOURCE ,
433462 image_request ['image' ]['source' ]['gcs_image_uri' ])
434463
@@ -444,7 +473,8 @@ def test_safe_search_no_results(self):
444473 credentials = _make_credentials ()
445474 client = self ._make_one (project = PROJECT , credentials = credentials ,
446475 use_gax = False )
447- client ._connection = _Connection (RETURNED )
476+ vision_api = client ._vision_api
477+ vision_api ._connection = _Connection (RETURNED )
448478
449479 image = client .image (content = IMAGE_CONTENT )
450480 safe_search = image .detect_safe_search ()
@@ -459,12 +489,14 @@ def test_image_properties_detection_from_source(self):
459489 credentials = _make_credentials ()
460490 client = self ._make_one (project = PROJECT , credentials = credentials ,
461491 use_gax = False )
462- client ._connection = _Connection (RETURNED )
492+ vision_api = client ._vision_api
493+ connection = _Connection (RETURNED )
494+ vision_api ._connection = connection
463495
464496 image = client .image (source_uri = IMAGE_SOURCE )
465497 image_properties = image .detect_properties ()
466498 self .assertIsInstance (image_properties , ImagePropertiesAnnotation )
467- image_request = client . _connection ._requested [0 ]['data' ]['requests' ][0 ]
499+ image_request = connection ._requested [0 ]['data' ]['requests' ][0 ]
468500 self .assertEqual (IMAGE_SOURCE ,
469501 image_request ['image' ]['source' ]['gcs_image_uri' ])
470502 self .assertEqual (0.42258179 , image_properties .colors [0 ].score )
@@ -482,7 +514,8 @@ def test_image_properties_no_results(self):
482514 credentials = _make_credentials ()
483515 client = self ._make_one (project = PROJECT , credentials = credentials ,
484516 use_gax = False )
485- client ._connection = _Connection (RETURNED )
517+ vision_api = client ._vision_api
518+ vision_api ._connection = _Connection (RETURNED )
486519
487520 image = client .image (content = IMAGE_CONTENT )
488521 image_properties = image .detect_properties ()
0 commit comments