17
17
import mock
18
18
19
19
20
+ def _make_credentials ():
21
+ import google .auth .credentials
22
+ return mock .Mock (spec = google .auth .credentials .Credentials )
23
+
24
+
20
25
class TestGAXClient (unittest .TestCase ):
21
26
def _get_target_class (self ):
22
27
from google .cloud .vision ._gax import _GAPICVisionAPI
@@ -32,12 +37,55 @@ def test_ctor(self):
32
37
api = self ._make_one (client )
33
38
self .assertIs (api ._client , client )
34
39
40
+ def test_gapic_credentials (self ):
41
+ from google .cloud .gapic .vision .v1 .image_annotator_client import (
42
+ ImageAnnotatorClient )
43
+ from google .cloud .vision import Client
44
+
45
+ # Mock the GAPIC ImageAnnotatorClient, whose arguments we
46
+ # want to check.
47
+ with mock .patch .object (ImageAnnotatorClient , '__init__' ) as iac :
48
+ iac .return_value = None
49
+
50
+ # Create the GAX client.
51
+ credentials = _make_credentials ()
52
+ client = Client (credentials = credentials , project = 'foo' )
53
+ self ._make_one (client = client )
54
+
55
+ # Assert that the GAPIC constructor was called once, and
56
+ # that the credentials were sent.
57
+ iac .assert_called_once ()
58
+ _ , _ , kwargs = iac .mock_calls [0 ]
59
+ self .assertIs (kwargs ['credentials' ], credentials )
60
+
61
+ def test_kwarg_lib_name (self ):
62
+ from google .cloud .gapic .vision .v1 .image_annotator_client import (
63
+ ImageAnnotatorClient )
64
+ from google .cloud .vision import __version__
65
+ from google .cloud .vision import Client
66
+
67
+ # Mock the GAPIC ImageAnnotatorClient, whose arguments we
68
+ # want to check.
69
+ with mock .patch .object (ImageAnnotatorClient , '__init__' ) as iac :
70
+ iac .return_value = None
71
+
72
+ # Create the GAX client.
73
+ client = Client (credentials = _make_credentials (), project = 'foo' )
74
+ self ._make_one (client = client )
75
+
76
+ # Assert that the GAPIC constructor was called once, and
77
+ # that lib_name and lib_version were sent.
78
+ iac .assert_called_once ()
79
+ _ , _ , kwargs = iac .mock_calls [0 ]
80
+ self .assertEqual (kwargs ['lib_name' ], 'gccl' )
81
+ self .assertEqual (kwargs ['lib_version' ], __version__ )
82
+
35
83
def test_annotation (self ):
36
84
from google .cloud .vision .feature import Feature
37
85
from google .cloud .vision .feature import FeatureTypes
38
86
from google .cloud .vision .image import Image
39
87
40
- client = mock .Mock (spec_set = [])
88
+ client = mock .Mock (spec_set = ['_credentials' ])
41
89
feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
42
90
image_content = b'abc 1 2 3'
43
91
image = Image (client , content = image_content )
@@ -64,7 +112,7 @@ def test_annotate_no_results(self):
64
112
from google .cloud .vision .feature import FeatureTypes
65
113
from google .cloud .vision .image import Image
66
114
67
- client = mock .Mock (spec_set = [])
115
+ client = mock .Mock (spec_set = ['_credentials' ])
68
116
feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
69
117
image_content = b'abc 1 2 3'
70
118
image = Image (client , content = image_content )
@@ -87,13 +135,13 @@ def test_annotate_no_results(self):
87
135
gax_api ._annotator_client .batch_annotate_images .assert_called ()
88
136
89
137
def test_annotate_multiple_results (self ):
90
- from google .cloud .grpc .vision .v1 import image_annotator_pb2
138
+ from google .cloud .proto .vision .v1 import image_annotator_pb2
91
139
from google .cloud .vision .annotations import Annotations
92
140
from google .cloud .vision .feature import Feature
93
141
from google .cloud .vision .feature import FeatureTypes
94
142
from google .cloud .vision .image import Image
95
143
96
- client = mock .Mock (spec_set = [])
144
+ client = mock .Mock (spec_set = ['_credentials' ])
97
145
feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
98
146
image_content = b'abc 1 2 3'
99
147
image = Image (client , content = image_content )
@@ -128,7 +176,7 @@ def _call_fut(self, feature):
128
176
def test__to_gapic_feature (self ):
129
177
from google .cloud .vision .feature import Feature
130
178
from google .cloud .vision .feature import FeatureTypes
131
- from google .cloud .grpc .vision .v1 import image_annotator_pb2
179
+ from google .cloud .proto .vision .v1 import image_annotator_pb2
132
180
133
181
feature = Feature (FeatureTypes .LABEL_DETECTION , 5 )
134
182
feature_pb = self ._call_fut (feature )
@@ -144,7 +192,7 @@ def _call_fut(self, image):
144
192
145
193
def test__to_gapic_image_content (self ):
146
194
from google .cloud .vision .image import Image
147
- from google .cloud .grpc .vision .v1 import image_annotator_pb2
195
+ from google .cloud .proto .vision .v1 import image_annotator_pb2
148
196
149
197
image_content = b'abc 1 2 3'
150
198
client = object ()
@@ -155,7 +203,7 @@ def test__to_gapic_image_content(self):
155
203
156
204
def test__to_gapic_image_uri (self ):
157
205
from google .cloud .vision .image import Image
158
- from google .cloud .grpc .vision .v1 import image_annotator_pb2
206
+ from google .cloud .proto .vision .v1 import image_annotator_pb2
159
207
160
208
image_uri = 'gs://1234/34.jpg'
161
209
client = object ()
0 commit comments