1515# limitations under the License.
1616"""Unit tests."""
1717
18+ import mock
1819import pytest
1920
2021from 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