1- # Copyright 2016 Google Inc. All Rights Reserved .
1+ # Copyright 2016 Google Inc. All rights reserved .
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
1414
1515import unittest
1616
17- _AUDIO_SOURCE_URI = 'gs://sample-bucket/sample-recording.flac'
18-
1917
2018class TestClient (unittest .TestCase ):
2119 SAMPLE_RATE = 16000
2220 HINTS = ['hi' ]
21+ AUDIO_SOURCE_URI = 'gs://sample-bucket/sample-recording.flac'
2322
2423 def _getTargetClass (self ):
2524 from google .cloud .speech .client import Client
@@ -78,9 +77,15 @@ def test_sync_recognize_content_with_optional_parameters(self):
7877 profanity_filter = True ,
7978 speech_context = self .HINTS )
8079
81- self .assertEqual (REQUEST ,
82- client .connection ._requested [0 ]['data' ])
83- self .assertEqual (response [0 ]['transcript' ], 'hello' )
80+ self .assertEqual (len (client .connection ._requested ), 1 )
81+ req = client .connection ._requested [0 ]
82+ self .assertEqual (len (req ), 3 )
83+ self .assertEqual (req ['data' ], REQUEST )
84+ self .assertEqual (req ['method' ], 'POST' )
85+ self .assertEqual (req ['path' ], 'syncrecognize' )
86+
87+ expected = SYNC_RECOGNIZE_RESPONSE ['results' ][0 ]['alternatives' ]
88+ self .assertEqual (response , expected )
8489
8590 def test_sync_recognize_source_uri_without_optional_parameters (self ):
8691 from google .cloud .speech .client import Encoding
@@ -93,7 +98,7 @@ def test_sync_recognize_source_uri_without_optional_parameters(self):
9398 'sampleRate' : 16000 ,
9499 },
95100 'audio' : {
96- 'uri' : _AUDIO_SOURCE_URI ,
101+ 'uri' : self . AUDIO_SOURCE_URI ,
97102 }
98103 }
99104 credentials = _Credentials ()
@@ -102,13 +107,19 @@ def test_sync_recognize_source_uri_without_optional_parameters(self):
102107
103108 encoding = Encoding .FLAC
104109
105- response = client .sync_recognize (None , _AUDIO_SOURCE_URI ,
110+ response = client .sync_recognize (None , self . AUDIO_SOURCE_URI ,
106111 encoding ,
107112 self .SAMPLE_RATE )
108113
109- self .assertEqual (REQUEST ,
110- client .connection ._requested [0 ]['data' ])
111- self .assertEqual (response [0 ]['transcript' ], 'hello' )
114+ self .assertEqual (len (client .connection ._requested ), 1 )
115+ req = client .connection ._requested [0 ]
116+ self .assertEqual (len (req ), 3 )
117+ self .assertEqual (req ['data' ], REQUEST )
118+ self .assertEqual (req ['method' ], 'POST' )
119+ self .assertEqual (req ['path' ], 'syncrecognize' )
120+
121+ expected = SYNC_RECOGNIZE_RESPONSE ['results' ][0 ]['alternatives' ]
122+ self .assertEqual (response , expected )
112123
113124 def test_sync_recognize_without_content_or_source_uri (self ):
114125 from google .cloud .speech .client import Encoding
@@ -128,15 +139,15 @@ def test_sync_recognize_with_content_and_source_uri(self):
128139 client = self ._makeOne (credentials = credentials )
129140
130141 with self .assertRaises (ValueError ):
131- client .sync_recognize (_AUDIO_CONTENT , _AUDIO_SOURCE_URI ,
142+ client .sync_recognize (_AUDIO_CONTENT , self . AUDIO_SOURCE_URI ,
132143 Encoding .FLAC , self .SAMPLE_RATE )
133144
134145 def test_sync_recognize_without_encoding (self ):
135146 credentials = _Credentials ()
136147 client = self ._makeOne (credentials = credentials )
137148
138149 with self .assertRaises (ValueError ):
139- client .sync_recognize (None , _AUDIO_SOURCE_URI , None ,
150+ client .sync_recognize (None , self . AUDIO_SOURCE_URI , None ,
140151 self .SAMPLE_RATE )
141152
142153 def test_sync_recognize_without_samplerate (self ):
@@ -146,7 +157,7 @@ def test_sync_recognize_without_samplerate(self):
146157 client = self ._makeOne (credentials = credentials )
147158
148159 with self .assertRaises (ValueError ):
149- client .sync_recognize (None , _AUDIO_SOURCE_URI , Encoding .FLAC ,
160+ client .sync_recognize (None , self . AUDIO_SOURCE_URI , Encoding .FLAC ,
150161 None )
151162
152163 def test_sync_recognize_with_empty_results (self ):
@@ -158,7 +169,7 @@ def test_sync_recognize_with_empty_results(self):
158169 client .connection = _Connection (SYNC_RECOGNIZE_EMPTY_RESPONSE )
159170
160171 with self .assertRaises (ValueError ):
161- client .sync_recognize (None , _AUDIO_SOURCE_URI , Encoding .FLAC ,
172+ client .sync_recognize (None , self . AUDIO_SOURCE_URI , Encoding .FLAC ,
162173 self .SAMPLE_RATE )
163174
164175
0 commit comments