Skip to content

Commit 662a670

Browse files
author
Jon Wayne Parrott
authored
Switch from oauth2client to google-auth (#2726)
* Removes all use of oauth2client from every package and tests. * Updates core to use google-auth's default credentials, project ID, and scoping logic. * Updates bigtable to use google-auth's scoping logic.
1 parent df62d29 commit 662a670

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

packages/google-cloud-speech/unit_tests/test_client.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ def _make_one(self, *args, **kw):
7979
def test_ctor(self):
8080
from google.cloud.speech.connection import Connection
8181

82-
creds = _Credentials()
82+
creds = object()
8383
http = object()
8484
client = self._make_one(credentials=creds, http=http)
8585
self.assertIsInstance(client._connection, Connection)
8686
self.assertTrue(client._connection.credentials is creds)
8787
self.assertTrue(client._connection.http is http)
8888

8989
def test_ctor_use_gax_preset(self):
90-
creds = _Credentials()
90+
creds = object()
9191
http = object()
9292
client = self._make_one(credentials=creds, http=http, use_gax=True)
9393
self.assertTrue(client._use_gax)
@@ -96,7 +96,7 @@ def test_create_sample_from_client(self):
9696
from google.cloud import speech
9797
from google.cloud.speech.sample import Sample
9898

99-
credentials = _Credentials()
99+
credentials = object()
100100
client = self._make_one(credentials=credentials)
101101

102102
sample = client.sample(source_uri=self.AUDIO_SOURCE_URI,
@@ -144,7 +144,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
144144
'content': _B64_AUDIO_CONTENT,
145145
}
146146
}
147-
credentials = _Credentials()
147+
credentials = object()
148148
client = self._make_one(credentials=credentials, use_gax=False)
149149
client._connection = _Connection(RETURNED)
150150

@@ -187,7 +187,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
187187
'uri': self.AUDIO_SOURCE_URI,
188188
}
189189
}
190-
credentials = _Credentials()
190+
credentials = object()
191191
client = self._make_one(credentials=credentials, use_gax=False)
192192
client._connection = _Connection(RETURNED)
193193

@@ -216,7 +216,7 @@ def test_sync_recognize_with_empty_results_no_gax(self):
216216
from google.cloud import speech
217217
from unit_tests._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE
218218

219-
credentials = _Credentials()
219+
credentials = object()
220220
client = self._make_one(credentials=credentials, use_gax=False)
221221
client._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)
222222

@@ -233,7 +233,7 @@ def test_sync_recognize_with_empty_results_gax(self):
233233
from google.cloud import speech
234234
from google.cloud.speech import _gax
235235

236-
credentials = _Credentials()
236+
credentials = object()
237237
client = self._make_one(credentials=credentials, use_gax=True)
238238
client._connection = _Connection()
239239
client._connection.credentials = credentials
@@ -276,7 +276,7 @@ def test_sync_recognize_with_gax(self):
276276
from google.cloud import speech
277277
from google.cloud.speech import _gax
278278

279-
creds = _Credentials()
279+
creds = object()
280280
client = self._make_one(credentials=creds, use_gax=True)
281281
client._connection = _Connection()
282282
client._connection.credentials = creds
@@ -336,7 +336,7 @@ def speech_api(channel=None):
336336
def test_async_supported_encodings(self):
337337
from google.cloud import speech
338338

339-
credentials = _Credentials()
339+
credentials = object()
340340
client = self._make_one(credentials=credentials)
341341
client._connection = _Connection({})
342342

@@ -353,7 +353,7 @@ def test_async_recognize_no_gax(self):
353353

354354
RETURNED = ASYNC_RECOGNIZE_RESPONSE
355355

356-
credentials = _Credentials()
356+
credentials = object()
357357
client = self._make_one(credentials=credentials, use_gax=False)
358358
client._connection = _Connection(RETURNED)
359359

@@ -375,7 +375,7 @@ def test_async_recognize_with_gax(self):
375375
from google.cloud.speech import _gax
376376
from google.cloud.speech.operation import Operation
377377

378-
credentials = _Credentials()
378+
credentials = object()
379379
client = self._make_one(credentials=credentials,
380380
use_gax=True)
381381
client._connection = _Connection()
@@ -416,9 +416,8 @@ def speech_api(channel=None):
416416

417417
def test_streaming_depends_on_gax(self):
418418
from google.cloud import speech
419-
from google.cloud._testing import _Monkey
420419

421-
credentials = _Credentials()
420+
credentials = object()
422421
client = self._make_one(credentials=credentials, use_gax=False)
423422
client.connection = _Connection()
424423
sample = client.sample(content=self.AUDIO_CONTENT,
@@ -437,7 +436,7 @@ def test_streaming_closed_stream(self):
437436
from google.cloud.speech.encoding import Encoding
438437

439438
stream = BytesIO(b'Some audio data...')
440-
credentials = _Credentials()
439+
credentials = object()
441440
client = self._make_one(credentials=credentials)
442441
client.connection = _Connection()
443442
client.connection.credentials = credentials
@@ -478,7 +477,7 @@ def test_stream_recognize_interim_results(self):
478477
from google.cloud.speech.result import StreamingSpeechResult
479478

480479
stream = BytesIO(b'Some audio data...')
481-
credentials = _Credentials()
480+
credentials = object()
482481
client = self._make_one(credentials=credentials)
483482
client.connection = _Connection()
484483
client.connection.credentials = credentials
@@ -554,7 +553,7 @@ def test_stream_recognize(self):
554553
from google.cloud.speech.encoding import Encoding
555554

556555
stream = BytesIO(b'Some audio data...')
557-
credentials = _Credentials()
556+
credentials = object()
558557
client = self._make_one(credentials=credentials)
559558
client.connection = _Connection()
560559
client.connection.credentials = credentials
@@ -610,7 +609,7 @@ def test_stream_recognize_no_results(self):
610609
from google.cloud.speech.encoding import Encoding
611610

612611
stream = BytesIO(b'Some audio data...')
613-
credentials = _Credentials()
612+
credentials = object()
614613
client = self._make_one(credentials=credentials)
615614
client.connection = _Connection()
616615
client.connection.credentials = credentials
@@ -646,7 +645,7 @@ def test_speech_api_with_gax(self):
646645

647646
from google.cloud.speech import _gax
648647

649-
creds = _Credentials()
648+
creds = object()
650649
client = self._make_one(credentials=creds, use_gax=True)
651650
client._connection = _Connection()
652651
client._connection.credentials = creds
@@ -679,14 +678,14 @@ def test_speech_api_without_gax(self):
679678
from google.cloud._http import Connection
680679
from google.cloud.speech.client import _JSONSpeechAPI
681680

682-
creds = _Credentials()
681+
creds = object()
683682
client = self._make_one(credentials=creds, use_gax=False)
684683
self.assertIsNone(client._speech_api)
685684
self.assertIsInstance(client.speech_api, _JSONSpeechAPI)
686685
self.assertIsInstance(client.speech_api._connection, Connection)
687686

688687
def test_speech_api_preset(self):
689-
creds = _Credentials()
688+
creds = object()
690689
client = self._make_one(credentials=creds)
691690
fake_api = object()
692691
client._speech_api = fake_api
@@ -724,23 +723,6 @@ def streaming_recognize(self, requests):
724723
yield response
725724

726725

727-
class _Credentials(object):
728-
729-
_scopes = ('https://www.googleapis.com/auth/cloud-platform',)
730-
731-
def __init__(self, authorized=None):
732-
self._authorized = authorized
733-
self._create_scoped_calls = 0
734-
735-
@staticmethod
736-
def create_scoped_required():
737-
return True
738-
739-
def create_scoped(self, scope):
740-
self._scopes = scope
741-
return self
742-
743-
744726
class _Connection(object):
745727

746728
def __init__(self, *responses):

0 commit comments

Comments
 (0)