1515# limitations under the License.
1616"""Unit tests."""
1717
18+ import mock
1819import pytest
1920
2021from google .cloud import scheduler_v1beta1
@@ -74,7 +75,10 @@ def test_list_jobs(self):
7475
7576 # Mock the API response
7677 channel = ChannelStub (responses = [expected_response ])
77- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
78+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
79+ with patch as create_channel :
80+ create_channel .return_value = channel
81+ client = scheduler_v1beta1 .CloudSchedulerClient ()
7882
7983 # Setup Request
8084 parent = client .location_path ('[PROJECT]' , '[LOCATION]' )
@@ -92,7 +96,10 @@ def test_list_jobs(self):
9296
9397 def test_list_jobs_exception (self ):
9498 channel = ChannelStub (responses = [CustomException ()])
95- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
99+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
100+ with patch as create_channel :
101+ create_channel .return_value = channel
102+ client = scheduler_v1beta1 .CloudSchedulerClient ()
96103
97104 # Setup request
98105 parent = client .location_path ('[PROJECT]' , '[LOCATION]' )
@@ -117,7 +124,10 @@ def test_get_job(self):
117124
118125 # Mock the API response
119126 channel = ChannelStub (responses = [expected_response ])
120- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
127+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
128+ with patch as create_channel :
129+ create_channel .return_value = channel
130+ client = scheduler_v1beta1 .CloudSchedulerClient ()
121131
122132 # Setup Request
123133 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -133,7 +143,10 @@ def test_get_job(self):
133143 def test_get_job_exception (self ):
134144 # Mock the API response
135145 channel = ChannelStub (responses = [CustomException ()])
136- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
146+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
147+ with patch as create_channel :
148+ create_channel .return_value = channel
149+ client = scheduler_v1beta1 .CloudSchedulerClient ()
137150
138151 # Setup request
139152 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -157,7 +170,10 @@ def test_create_job(self):
157170
158171 # Mock the API response
159172 channel = ChannelStub (responses = [expected_response ])
160- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
173+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
174+ with patch as create_channel :
175+ create_channel .return_value = channel
176+ client = scheduler_v1beta1 .CloudSchedulerClient ()
161177
162178 # Setup Request
163179 parent = client .location_path ('[PROJECT]' , '[LOCATION]' )
@@ -175,7 +191,10 @@ def test_create_job(self):
175191 def test_create_job_exception (self ):
176192 # Mock the API response
177193 channel = ChannelStub (responses = [CustomException ()])
178- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
194+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
195+ with patch as create_channel :
196+ create_channel .return_value = channel
197+ client = scheduler_v1beta1 .CloudSchedulerClient ()
179198
180199 # Setup request
181200 parent = client .location_path ('[PROJECT]' , '[LOCATION]' )
@@ -200,7 +219,10 @@ def test_update_job(self):
200219
201220 # Mock the API response
202221 channel = ChannelStub (responses = [expected_response ])
203- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
222+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
223+ with patch as create_channel :
224+ create_channel .return_value = channel
225+ client = scheduler_v1beta1 .CloudSchedulerClient ()
204226
205227 # Setup Request
206228 job = {}
@@ -216,7 +238,10 @@ def test_update_job(self):
216238 def test_update_job_exception (self ):
217239 # Mock the API response
218240 channel = ChannelStub (responses = [CustomException ()])
219- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
241+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
242+ with patch as create_channel :
243+ create_channel .return_value = channel
244+ client = scheduler_v1beta1 .CloudSchedulerClient ()
220245
221246 # Setup request
222247 job = {}
@@ -226,7 +251,10 @@ def test_update_job_exception(self):
226251
227252 def test_delete_job (self ):
228253 channel = ChannelStub ()
229- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
254+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
255+ with patch as create_channel :
256+ create_channel .return_value = channel
257+ client = scheduler_v1beta1 .CloudSchedulerClient ()
230258
231259 # Setup Request
232260 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -241,7 +269,10 @@ def test_delete_job(self):
241269 def test_delete_job_exception (self ):
242270 # Mock the API response
243271 channel = ChannelStub (responses = [CustomException ()])
244- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
272+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
273+ with patch as create_channel :
274+ create_channel .return_value = channel
275+ client = scheduler_v1beta1 .CloudSchedulerClient ()
245276
246277 # Setup request
247278 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -265,7 +296,10 @@ def test_pause_job(self):
265296
266297 # Mock the API response
267298 channel = ChannelStub (responses = [expected_response ])
268- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
299+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
300+ with patch as create_channel :
301+ create_channel .return_value = channel
302+ client = scheduler_v1beta1 .CloudSchedulerClient ()
269303
270304 # Setup Request
271305 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -281,7 +315,10 @@ def test_pause_job(self):
281315 def test_pause_job_exception (self ):
282316 # Mock the API response
283317 channel = ChannelStub (responses = [CustomException ()])
284- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
318+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
319+ with patch as create_channel :
320+ create_channel .return_value = channel
321+ client = scheduler_v1beta1 .CloudSchedulerClient ()
285322
286323 # Setup request
287324 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -305,7 +342,10 @@ def test_resume_job(self):
305342
306343 # Mock the API response
307344 channel = ChannelStub (responses = [expected_response ])
308- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
345+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
346+ with patch as create_channel :
347+ create_channel .return_value = channel
348+ client = scheduler_v1beta1 .CloudSchedulerClient ()
309349
310350 # Setup Request
311351 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -321,7 +361,10 @@ def test_resume_job(self):
321361 def test_resume_job_exception (self ):
322362 # Mock the API response
323363 channel = ChannelStub (responses = [CustomException ()])
324- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
364+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
365+ with patch as create_channel :
366+ create_channel .return_value = channel
367+ client = scheduler_v1beta1 .CloudSchedulerClient ()
325368
326369 # Setup request
327370 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -345,7 +388,10 @@ def test_run_job(self):
345388
346389 # Mock the API response
347390 channel = ChannelStub (responses = [expected_response ])
348- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
391+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
392+ with patch as create_channel :
393+ create_channel .return_value = channel
394+ client = scheduler_v1beta1 .CloudSchedulerClient ()
349395
350396 # Setup Request
351397 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
@@ -361,7 +407,10 @@ def test_run_job(self):
361407 def test_run_job_exception (self ):
362408 # Mock the API response
363409 channel = ChannelStub (responses = [CustomException ()])
364- client = scheduler_v1beta1 .CloudSchedulerClient (channel = channel )
410+ patch = mock .patch ('google.api_core.grpc_helpers.create_channel' )
411+ with patch as create_channel :
412+ create_channel .return_value = channel
413+ client = scheduler_v1beta1 .CloudSchedulerClient ()
365414
366415 # Setup request
367416 name = client .job_path ('[PROJECT]' , '[LOCATION]' , '[JOB]' )
0 commit comments