1919from google .api_core import client_info as client_info_lib
2020from google .cloud .storage .asyncio import async_grpc_client
2121from google .cloud .storage import __version__
22+ from google .api_core import client_options
2223
2324
2425def _make_credentials (spec = None ):
@@ -157,36 +158,31 @@ def test_grpc_client_property(self, mock_grpc_gapic_client):
157158 assert retrieved_client is mock_grpc_gapic_client .return_value
158159
159160 @mock .patch ("google.cloud._storage_v2.StorageAsyncClient" )
160- def test_grpc_client_with_anon_creds (self , mock_grpc_gapic_client ):
161+ @mock .patch (
162+ "google.cloud.storage.asyncio.async_grpc_client.grpc.aio.insecure_channel"
163+ )
164+ def test_grpc_client_with_anon_creds (
165+ self , mock_insecure_channel , mock_async_storage_client
166+ ):
161167 # Arrange
162- mock_transport_cls = mock .MagicMock ()
163- mock_grpc_gapic_client .get_transport_class .return_value = mock_transport_cls
164- channel_sentinel = mock .sentinel .channel
165-
166- mock_transport_cls .create_channel .return_value = channel_sentinel
167- mock_transport_cls .return_value = mock .sentinel .transport
168+ mock_channel = mock .MagicMock ()
169+ mock_insecure_channel .return_value = mock_channel
168170
169171 # Act
170- anonymous_creds = AnonymousCredentials ()
171- client = async_grpc_client .AsyncGrpcClient (credentials = anonymous_creds )
172- retrieved_client = client .grpc_client
172+ client = async_grpc_client .AsyncGrpcClient (
173+ client_options = client_options .ClientOptions (
174+ api_endpoint = "my-grpc-endpoint"
175+ ),
176+ credentials = AnonymousCredentials (),
177+ )
173178
174179 # Assert
175- assert retrieved_client is mock_grpc_gapic_client .return_value
176-
177- kwargs = mock_grpc_gapic_client .call_args .kwargs
178- client_info = kwargs ["client_info" ]
179- agent_version = f"gcloud-python/{ __version__ } "
180- assert agent_version in client_info .user_agent
181- primary_user_agent = client_info .to_user_agent ()
182- expected_options = (("grpc.primary_user_agent" , primary_user_agent ),)
180+ assert client .grpc_client is mock_async_storage_client .return_value
181+ mock_insecure_channel .assert_called_once_with ("my-grpc-endpoint" )
183182
184- mock_transport_cls .create_channel .assert_called_once_with (
185- attempt_direct_path = True ,
186- credentials = anonymous_creds ,
187- options = expected_options ,
188- )
189- mock_transport_cls .assert_called_once_with (channel = channel_sentinel )
183+ kwargs = mock_async_storage_client .call_args .kwargs
184+ transport = kwargs ["transport" ]
185+ assert isinstance (transport ._credentials , AnonymousCredentials )
190186
191187 @mock .patch ("google.cloud._storage_v2.StorageAsyncClient" )
192188 def test_user_agent_with_custom_client_info (self , mock_async_storage_client ):
@@ -221,9 +217,7 @@ async def test_delete_object(self, mock_async_storage_client):
221217 mock_gapic_client = mock .AsyncMock ()
222218 mock_async_storage_client .return_value = mock_gapic_client
223219
224- client = async_grpc_client .AsyncGrpcClient (
225- credentials = _make_credentials (spec = AnonymousCredentials )
226- )
220+ client = async_grpc_client .AsyncGrpcClient (credentials = _make_credentials ())
227221
228222 bucket_name = "bucket"
229223 object_name = "object"
@@ -264,9 +258,7 @@ async def test_get_object(self, mock_async_storage_client):
264258 mock_gapic_client = mock .AsyncMock ()
265259 mock_async_storage_client .return_value = mock_gapic_client
266260
267- client = async_grpc_client .AsyncGrpcClient (
268- credentials = _make_credentials (spec = AnonymousCredentials )
269- )
261+ client = async_grpc_client .AsyncGrpcClient (credentials = _make_credentials ())
270262
271263 bucket_name = "bucket"
272264 object_name = "object"
@@ -293,9 +285,7 @@ async def test_get_object_with_all_parameters(self, mock_async_storage_client):
293285 mock_gapic_client = mock .AsyncMock ()
294286 mock_async_storage_client .return_value = mock_gapic_client
295287
296- client = async_grpc_client .AsyncGrpcClient (
297- credentials = _make_credentials (spec = AnonymousCredentials )
298- )
288+ client = async_grpc_client .AsyncGrpcClient (credentials = _make_credentials ())
299289
300290 bucket_name = "bucket"
301291 object_name = "object"
0 commit comments