Skip to content

Commit ce304b2

Browse files
yoshi-automationtseaver
authored andcommitted
Pick up fixes to GAPIC generator. (#6503)
1 parent 86937bd commit ce304b2

6 files changed

Lines changed: 272 additions & 66 deletions

File tree

packages/google-cloud-pubsub/google/cloud/pubsub_v1/gapic/publisher_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(self,
103103
transport=None,
104104
channel=None,
105105
credentials=None,
106-
client_config=publisher_client_config.config,
106+
client_config=None,
107107
client_info=None):
108108
"""Constructor.
109109
@@ -136,13 +136,20 @@ def __init__(self,
136136
your own client library.
137137
"""
138138
# Raise deprecation warnings for things we want to go away.
139-
if client_config:
140-
warnings.warn('The `client_config` argument is deprecated.',
141-
PendingDeprecationWarning)
139+
if client_config is not None:
140+
warnings.warn(
141+
'The `client_config` argument is deprecated.',
142+
PendingDeprecationWarning,
143+
stacklevel=2)
144+
else:
145+
client_config = publisher_client_config.config
146+
142147
if channel:
143148
warnings.warn(
144149
'The `channel` argument is deprecated; use '
145-
'`transport` instead.', PendingDeprecationWarning)
150+
'`transport` instead.',
151+
PendingDeprecationWarning,
152+
stacklevel=2)
146153

147154
# Instantiate the transport.
148155
# The transport is responsible for handling serialization and

packages/google-cloud-pubsub/google/cloud/pubsub_v1/gapic/subscriber_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(self,
124124
transport=None,
125125
channel=None,
126126
credentials=None,
127-
client_config=subscriber_client_config.config,
127+
client_config=None,
128128
client_info=None):
129129
"""Constructor.
130130
@@ -157,13 +157,20 @@ def __init__(self,
157157
your own client library.
158158
"""
159159
# Raise deprecation warnings for things we want to go away.
160-
if client_config:
161-
warnings.warn('The `client_config` argument is deprecated.',
162-
PendingDeprecationWarning)
160+
if client_config is not None:
161+
warnings.warn(
162+
'The `client_config` argument is deprecated.',
163+
PendingDeprecationWarning,
164+
stacklevel=2)
165+
else:
166+
client_config = subscriber_client_config.config
167+
163168
if channel:
164169
warnings.warn(
165170
'The `channel` argument is deprecated; use '
166-
'`transport` instead.', PendingDeprecationWarning)
171+
'`transport` instead.',
172+
PendingDeprecationWarning,
173+
stacklevel=2)
167174

168175
# Instantiate the transport.
169176
# The transport is responsible for handling serialization and

packages/google-cloud-pubsub/google/cloud/pubsub_v1/gapic/transports/publisher_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self,
6666
credentials=credentials,
6767
)
6868

69+
self._channel = channel
70+
6971
# gRPC uses objects called "stubs" that are bound to the
7072
# channel and provide a basic method for each RPC.
7173
self._stubs = {
@@ -96,6 +98,15 @@ def create_channel(cls,
9698
scopes=cls._OAUTH_SCOPES,
9799
)
98100

101+
@property
102+
def channel(self):
103+
"""The gRPC channel used by the transport.
104+
105+
Returns:
106+
grpc.Channel: A gRPC channel object.
107+
"""
108+
return self._channel
109+
99110
@property
100111
def create_topic(self):
101112
"""Return the gRPC stub for {$apiMethod.name}.

packages/google-cloud-pubsub/google/cloud/pubsub_v1/gapic/transports/subscriber_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self,
6666
credentials=credentials,
6767
)
6868

69+
self._channel = channel
70+
6971
# gRPC uses objects called "stubs" that are bound to the
7072
# channel and provide a basic method for each RPC.
7173
self._stubs = {
@@ -96,6 +98,15 @@ def create_channel(cls,
9698
scopes=cls._OAUTH_SCOPES,
9799
)
98100

101+
@property
102+
def channel(self):
103+
"""The gRPC channel used by the transport.
104+
105+
Returns:
106+
grpc.Channel: A gRPC channel object.
107+
"""
108+
return self._channel
109+
99110
@property
100111
def create_subscription(self):
101112
"""Return the gRPC stub for {$apiMethod.name}.

packages/google-cloud-pubsub/tests/unit/gapic/v1/test_publisher_client_v1.py

Lines changed: 81 additions & 20 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.pubsub_v1.gapic import publisher_client
@@ -73,7 +74,10 @@ def test_create_topic(self):
7374

7475
# Mock the API response
7576
channel = ChannelStub(responses=[expected_response])
76-
client = publisher_client.PublisherClient(channel=channel)
77+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
78+
with patch as create_channel:
79+
create_channel.return_value = channel
80+
client = publisher_client.PublisherClient()
7781

7882
# Setup Request
7983
name = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -89,7 +93,10 @@ def test_create_topic(self):
8993
def test_create_topic_exception(self):
9094
# Mock the API response
9195
channel = ChannelStub(responses=[CustomException()])
92-
client = publisher_client.PublisherClient(channel=channel)
96+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
97+
with patch as create_channel:
98+
create_channel.return_value = channel
99+
client = publisher_client.PublisherClient()
93100

94101
# Setup request
95102
name = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -105,7 +112,10 @@ def test_update_topic(self):
105112

106113
# Mock the API response
107114
channel = ChannelStub(responses=[expected_response])
108-
client = publisher_client.PublisherClient(channel=channel)
115+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
116+
with patch as create_channel:
117+
create_channel.return_value = channel
118+
client = publisher_client.PublisherClient()
109119

110120
# Setup Request
111121
topic = {}
@@ -123,7 +133,10 @@ def test_update_topic(self):
123133
def test_update_topic_exception(self):
124134
# Mock the API response
125135
channel = ChannelStub(responses=[CustomException()])
126-
client = publisher_client.PublisherClient(channel=channel)
136+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
137+
with patch as create_channel:
138+
create_channel.return_value = channel
139+
client = publisher_client.PublisherClient()
127140

128141
# Setup request
129142
topic = {}
@@ -141,7 +154,10 @@ def test_publish(self):
141154

142155
# Mock the API response
143156
channel = ChannelStub(responses=[expected_response])
144-
client = publisher_client.PublisherClient(channel=channel)
157+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
158+
with patch as create_channel:
159+
create_channel.return_value = channel
160+
client = publisher_client.PublisherClient()
145161

146162
# Setup Request
147163
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -161,7 +177,10 @@ def test_publish(self):
161177
def test_publish_exception(self):
162178
# Mock the API response
163179
channel = ChannelStub(responses=[CustomException()])
164-
client = publisher_client.PublisherClient(channel=channel)
180+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
181+
with patch as create_channel:
182+
create_channel.return_value = channel
183+
client = publisher_client.PublisherClient()
165184

166185
# Setup request
167186
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -180,7 +199,10 @@ def test_get_topic(self):
180199

181200
# Mock the API response
182201
channel = ChannelStub(responses=[expected_response])
183-
client = publisher_client.PublisherClient(channel=channel)
202+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
203+
with patch as create_channel:
204+
create_channel.return_value = channel
205+
client = publisher_client.PublisherClient()
184206

185207
# Setup Request
186208
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -196,7 +218,10 @@ def test_get_topic(self):
196218
def test_get_topic_exception(self):
197219
# Mock the API response
198220
channel = ChannelStub(responses=[CustomException()])
199-
client = publisher_client.PublisherClient(channel=channel)
221+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
222+
with patch as create_channel:
223+
create_channel.return_value = channel
224+
client = publisher_client.PublisherClient()
200225

201226
# Setup request
202227
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -217,7 +242,10 @@ def test_list_topics(self):
217242

218243
# Mock the API response
219244
channel = ChannelStub(responses=[expected_response])
220-
client = publisher_client.PublisherClient(channel=channel)
245+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
246+
with patch as create_channel:
247+
create_channel.return_value = channel
248+
client = publisher_client.PublisherClient()
221249

222250
# Setup Request
223251
project = client.project_path('[PROJECT]')
@@ -235,7 +263,10 @@ def test_list_topics(self):
235263

236264
def test_list_topics_exception(self):
237265
channel = ChannelStub(responses=[CustomException()])
238-
client = publisher_client.PublisherClient(channel=channel)
266+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
267+
with patch as create_channel:
268+
create_channel.return_value = channel
269+
client = publisher_client.PublisherClient()
239270

240271
# Setup request
241272
project = client.project_path('[PROJECT]')
@@ -258,7 +289,10 @@ def test_list_topic_subscriptions(self):
258289

259290
# Mock the API response
260291
channel = ChannelStub(responses=[expected_response])
261-
client = publisher_client.PublisherClient(channel=channel)
292+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
293+
with patch as create_channel:
294+
create_channel.return_value = channel
295+
client = publisher_client.PublisherClient()
262296

263297
# Setup Request
264298
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -277,7 +311,10 @@ def test_list_topic_subscriptions(self):
277311

278312
def test_list_topic_subscriptions_exception(self):
279313
channel = ChannelStub(responses=[CustomException()])
280-
client = publisher_client.PublisherClient(channel=channel)
314+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
315+
with patch as create_channel:
316+
create_channel.return_value = channel
317+
client = publisher_client.PublisherClient()
281318

282319
# Setup request
283320
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -288,7 +325,10 @@ def test_list_topic_subscriptions_exception(self):
288325

289326
def test_delete_topic(self):
290327
channel = ChannelStub()
291-
client = publisher_client.PublisherClient(channel=channel)
328+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
329+
with patch as create_channel:
330+
create_channel.return_value = channel
331+
client = publisher_client.PublisherClient()
292332

293333
# Setup Request
294334
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -303,7 +343,10 @@ def test_delete_topic(self):
303343
def test_delete_topic_exception(self):
304344
# Mock the API response
305345
channel = ChannelStub(responses=[CustomException()])
306-
client = publisher_client.PublisherClient(channel=channel)
346+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
347+
with patch as create_channel:
348+
create_channel.return_value = channel
349+
client = publisher_client.PublisherClient()
307350

308351
# Setup request
309352
topic = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -320,7 +363,10 @@ def test_set_iam_policy(self):
320363

321364
# Mock the API response
322365
channel = ChannelStub(responses=[expected_response])
323-
client = publisher_client.PublisherClient(channel=channel)
366+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
367+
with patch as create_channel:
368+
create_channel.return_value = channel
369+
client = publisher_client.PublisherClient()
324370

325371
# Setup Request
326372
resource = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -338,7 +384,10 @@ def test_set_iam_policy(self):
338384
def test_set_iam_policy_exception(self):
339385
# Mock the API response
340386
channel = ChannelStub(responses=[CustomException()])
341-
client = publisher_client.PublisherClient(channel=channel)
387+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
388+
with patch as create_channel:
389+
create_channel.return_value = channel
390+
client = publisher_client.PublisherClient()
342391

343392
# Setup request
344393
resource = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -356,7 +405,10 @@ def test_get_iam_policy(self):
356405

357406
# Mock the API response
358407
channel = ChannelStub(responses=[expected_response])
359-
client = publisher_client.PublisherClient(channel=channel)
408+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
409+
with patch as create_channel:
410+
create_channel.return_value = channel
411+
client = publisher_client.PublisherClient()
360412

361413
# Setup Request
362414
resource = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -373,7 +425,10 @@ def test_get_iam_policy(self):
373425
def test_get_iam_policy_exception(self):
374426
# Mock the API response
375427
channel = ChannelStub(responses=[CustomException()])
376-
client = publisher_client.PublisherClient(channel=channel)
428+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
429+
with patch as create_channel:
430+
create_channel.return_value = channel
431+
client = publisher_client.PublisherClient()
377432

378433
# Setup request
379434
resource = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -389,7 +444,10 @@ def test_test_iam_permissions(self):
389444

390445
# Mock the API response
391446
channel = ChannelStub(responses=[expected_response])
392-
client = publisher_client.PublisherClient(channel=channel)
447+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
448+
with patch as create_channel:
449+
create_channel.return_value = channel
450+
client = publisher_client.PublisherClient()
393451

394452
# Setup Request
395453
resource = client.topic_path('[PROJECT]', '[TOPIC]')
@@ -407,7 +465,10 @@ def test_test_iam_permissions(self):
407465
def test_test_iam_permissions_exception(self):
408466
# Mock the API response
409467
channel = ChannelStub(responses=[CustomException()])
410-
client = publisher_client.PublisherClient(channel=channel)
468+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
469+
with patch as create_channel:
470+
create_channel.return_value = channel
471+
client = publisher_client.PublisherClient()
411472

412473
# Setup request
413474
resource = client.topic_path('[PROJECT]', '[TOPIC]')

0 commit comments

Comments
 (0)