@@ -128,3 +128,44 @@ def test_wrap_errors_streaming(wrap_stream_errors):
128128
129129 assert result == wrap_stream_errors .return_value
130130 wrap_stream_errors .assert_called_once_with (callable_ )
131+
132+
133+ @mock .patch (
134+ 'google.auth.default' ,
135+ return_value = (mock .sentinel .credentials , mock .sentinel .projet ))
136+ @mock .patch ('google.auth.transport.grpc.secure_authorized_channel' )
137+ def test_create_channel_implicit (secure_authorized_channel , default ):
138+ target = 'example.com:443'
139+
140+ channel = grpc_helpers .create_channel (target )
141+
142+ assert channel is secure_authorized_channel .return_value
143+ default .assert_called_once_with (scopes = None )
144+ secure_authorized_channel .assert_called_once_with (
145+ mock .sentinel .credentials , mock .ANY , target )
146+
147+
148+ @mock .patch (
149+ 'google.auth.default' ,
150+ return_value = (mock .sentinel .credentials , mock .sentinel .projet ))
151+ @mock .patch ('google.auth.transport.grpc.secure_authorized_channel' )
152+ def test_create_channel_implicit_with_scopes (
153+ secure_authorized_channel , default ):
154+ target = 'example.com:443'
155+
156+ channel = grpc_helpers .create_channel (target , scopes = ['one' , 'two' ])
157+
158+ assert channel is secure_authorized_channel .return_value
159+ default .assert_called_once_with (scopes = ['one' , 'two' ])
160+
161+
162+ @mock .patch ('google.auth.transport.grpc.secure_authorized_channel' )
163+ def test_create_channel_explicit (secure_authorized_channel ):
164+ target = 'example.com:443'
165+
166+ channel = grpc_helpers .create_channel (
167+ target , credentials = mock .sentinel .credentials )
168+
169+ assert channel is secure_authorized_channel .return_value
170+ secure_authorized_channel .assert_called_once_with (
171+ mock .sentinel .credentials , mock .ANY , target )
0 commit comments