Skip to content

Commit b2eed88

Browse files
yoshi-automationtseaver
authored andcommitted
Pick up fixes to GAPIC generator. (googleapis#6505)
1 parent 2298937 commit b2eed88

3 files changed

Lines changed: 88 additions & 21 deletions

File tree

scheduler/google/cloud/scheduler_v1beta1/gapic/cloud_scheduler_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self,
106106
transport=None,
107107
channel=None,
108108
credentials=None,
109-
client_config=cloud_scheduler_client_config.config,
109+
client_config=None,
110110
client_info=None):
111111
"""Constructor.
112112
@@ -139,13 +139,20 @@ def __init__(self,
139139
your own client library.
140140
"""
141141
# Raise deprecation warnings for things we want to go away.
142-
if client_config:
143-
warnings.warn('The `client_config` argument is deprecated.',
144-
PendingDeprecationWarning)
142+
if client_config is not None:
143+
warnings.warn(
144+
'The `client_config` argument is deprecated.',
145+
PendingDeprecationWarning,
146+
stacklevel=2)
147+
else:
148+
client_config = cloud_scheduler_client_config.config
149+
145150
if channel:
146151
warnings.warn(
147152
'The `channel` argument is deprecated; use '
148-
'`transport` instead.', PendingDeprecationWarning)
153+
'`transport` instead.',
154+
PendingDeprecationWarning,
155+
stacklevel=2)
149156

150157
# Instantiate the transport.
151158
# The transport is responsible for handling serialization and

scheduler/google/cloud/scheduler_v1beta1/gapic/transports/cloud_scheduler_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(self,
6262
credentials=credentials,
6363
)
6464

65+
self._channel = channel
66+
6567
# gRPC uses objects called "stubs" that are bound to the
6668
# channel and provide a basic method for each RPC.
6769
self._stubs = {
@@ -92,6 +94,15 @@ def create_channel(cls,
9294
scopes=cls._OAUTH_SCOPES,
9395
)
9496

97+
@property
98+
def channel(self):
99+
"""The gRPC channel used by the transport.
100+
101+
Returns:
102+
grpc.Channel: A gRPC channel object.
103+
"""
104+
return self._channel
105+
95106
@property
96107
def list_jobs(self):
97108
"""Return the gRPC stub for {$apiMethod.name}.

scheduler/tests/unit/gapic/v1beta1/test_cloud_scheduler_client_v1beta1.py

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
"""Unit tests."""
1717

18+
import mock
1819
import pytest
1920

2021
from 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

Comments
 (0)