14
14
15
15
import unittest
16
16
17
+ import mock
18
+
19
+
20
+ def _make_credentials ():
21
+ import google .auth .credentials
22
+ return mock .Mock (spec = google .auth .credentials .Credentials )
23
+
17
24
18
25
def _make_result (alternatives = ()):
19
26
from google .cloud .grpc .speech .v1beta1 import cloud_speech_pb2
@@ -79,15 +86,15 @@ def _make_one(self, *args, **kw):
79
86
def test_ctor (self ):
80
87
from google .cloud .speech .connection import Connection
81
88
82
- creds = object ()
89
+ creds = _make_credentials ()
83
90
http = object ()
84
91
client = self ._make_one (credentials = creds , http = http )
85
92
self .assertIsInstance (client ._connection , Connection )
86
93
self .assertTrue (client ._connection .credentials is creds )
87
94
self .assertTrue (client ._connection .http is http )
88
95
89
96
def test_ctor_use_gax_preset (self ):
90
- creds = object ()
97
+ creds = _make_credentials ()
91
98
http = object ()
92
99
client = self ._make_one (credentials = creds , http = http , use_gax = True )
93
100
self .assertTrue (client ._use_gax )
@@ -96,7 +103,7 @@ def test_create_sample_from_client(self):
96
103
from google .cloud import speech
97
104
from google .cloud .speech .sample import Sample
98
105
99
- credentials = object ()
106
+ credentials = _make_credentials ()
100
107
client = self ._make_one (credentials = credentials )
101
108
102
109
sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
@@ -144,7 +151,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
144
151
'content' : _B64_AUDIO_CONTENT ,
145
152
}
146
153
}
147
- credentials = object ()
154
+ credentials = _make_credentials ()
148
155
client = self ._make_one (credentials = credentials , use_gax = False )
149
156
client ._connection = _Connection (RETURNED )
150
157
@@ -187,7 +194,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
187
194
'uri' : self .AUDIO_SOURCE_URI ,
188
195
}
189
196
}
190
- credentials = object ()
197
+ credentials = _make_credentials ()
191
198
client = self ._make_one (credentials = credentials , use_gax = False )
192
199
client ._connection = _Connection (RETURNED )
193
200
@@ -216,7 +223,7 @@ def test_sync_recognize_with_empty_results_no_gax(self):
216
223
from google .cloud import speech
217
224
from unit_tests ._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE
218
225
219
- credentials = object ()
226
+ credentials = _make_credentials ()
220
227
client = self ._make_one (credentials = credentials , use_gax = False )
221
228
client ._connection = _Connection (SYNC_RECOGNIZE_EMPTY_RESPONSE )
222
229
@@ -233,7 +240,7 @@ def test_sync_recognize_with_empty_results_gax(self):
233
240
from google .cloud import speech
234
241
from google .cloud .speech import _gax
235
242
236
- credentials = object ()
243
+ credentials = _make_credentials ()
237
244
client = self ._make_one (credentials = credentials , use_gax = True )
238
245
client ._connection = _Connection ()
239
246
client ._connection .credentials = credentials
@@ -276,7 +283,7 @@ def test_sync_recognize_with_gax(self):
276
283
from google .cloud import speech
277
284
from google .cloud .speech import _gax
278
285
279
- creds = object ()
286
+ creds = _make_credentials ()
280
287
client = self ._make_one (credentials = creds , use_gax = True )
281
288
client ._connection = _Connection ()
282
289
client ._connection .credentials = creds
@@ -336,7 +343,7 @@ def speech_api(channel=None):
336
343
def test_async_supported_encodings (self ):
337
344
from google .cloud import speech
338
345
339
- credentials = object ()
346
+ credentials = _make_credentials ()
340
347
client = self ._make_one (credentials = credentials )
341
348
client ._connection = _Connection ({})
342
349
@@ -353,7 +360,7 @@ def test_async_recognize_no_gax(self):
353
360
354
361
RETURNED = ASYNC_RECOGNIZE_RESPONSE
355
362
356
- credentials = object ()
363
+ credentials = _make_credentials ()
357
364
client = self ._make_one (credentials = credentials , use_gax = False )
358
365
client ._connection = _Connection (RETURNED )
359
366
@@ -375,7 +382,7 @@ def test_async_recognize_with_gax(self):
375
382
from google .cloud .speech import _gax
376
383
from google .cloud .speech .operation import Operation
377
384
378
- credentials = object ()
385
+ credentials = _make_credentials ()
379
386
client = self ._make_one (credentials = credentials ,
380
387
use_gax = True )
381
388
client ._connection = _Connection ()
@@ -417,7 +424,7 @@ def speech_api(channel=None):
417
424
def test_streaming_depends_on_gax (self ):
418
425
from google .cloud import speech
419
426
420
- credentials = object ()
427
+ credentials = _make_credentials ()
421
428
client = self ._make_one (credentials = credentials , use_gax = False )
422
429
client .connection = _Connection ()
423
430
sample = client .sample (content = self .AUDIO_CONTENT ,
@@ -436,7 +443,7 @@ def test_streaming_closed_stream(self):
436
443
from google .cloud .speech .encoding import Encoding
437
444
438
445
stream = BytesIO (b'Some audio data...' )
439
- credentials = object ()
446
+ credentials = _make_credentials ()
440
447
client = self ._make_one (credentials = credentials )
441
448
client .connection = _Connection ()
442
449
client .connection .credentials = credentials
@@ -477,7 +484,7 @@ def test_stream_recognize_interim_results(self):
477
484
from google .cloud .speech .result import StreamingSpeechResult
478
485
479
486
stream = BytesIO (b'Some audio data...' )
480
- credentials = object ()
487
+ credentials = _make_credentials ()
481
488
client = self ._make_one (credentials = credentials )
482
489
client .connection = _Connection ()
483
490
client .connection .credentials = credentials
@@ -553,7 +560,7 @@ def test_stream_recognize(self):
553
560
from google .cloud .speech .encoding import Encoding
554
561
555
562
stream = BytesIO (b'Some audio data...' )
556
- credentials = object ()
563
+ credentials = _make_credentials ()
557
564
client = self ._make_one (credentials = credentials )
558
565
client .connection = _Connection ()
559
566
client .connection .credentials = credentials
@@ -609,7 +616,7 @@ def test_stream_recognize_no_results(self):
609
616
from google .cloud .speech .encoding import Encoding
610
617
611
618
stream = BytesIO (b'Some audio data...' )
612
- credentials = object ()
619
+ credentials = _make_credentials ()
613
620
client = self ._make_one (credentials = credentials )
614
621
client .connection = _Connection ()
615
622
client .connection .credentials = credentials
@@ -645,7 +652,7 @@ def test_speech_api_with_gax(self):
645
652
646
653
from google .cloud .speech import _gax
647
654
648
- creds = object ()
655
+ creds = _make_credentials ()
649
656
client = self ._make_one (credentials = creds , use_gax = True )
650
657
client ._connection = _Connection ()
651
658
client ._connection .credentials = creds
@@ -678,14 +685,14 @@ def test_speech_api_without_gax(self):
678
685
from google .cloud ._http import Connection
679
686
from google .cloud .speech .client import _JSONSpeechAPI
680
687
681
- creds = object ()
688
+ creds = _make_credentials ()
682
689
client = self ._make_one (credentials = creds , use_gax = False )
683
690
self .assertIsNone (client ._speech_api )
684
691
self .assertIsInstance (client .speech_api , _JSONSpeechAPI )
685
692
self .assertIsInstance (client .speech_api ._connection , Connection )
686
693
687
694
def test_speech_api_preset (self ):
688
- creds = object ()
695
+ creds = _make_credentials ()
689
696
client = self ._make_one (credentials = creds )
690
697
fake_api = object ()
691
698
client ._speech_api = fake_api
0 commit comments