| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,8 +65,10 @@ def _create_async_grpc_client( | |||
| 65 | 65 | transport_cls = storage_v2.StorageAsyncClient.get_transport_class( | |
| 66 | 66 | "grpc_asyncio" | |
| 67 | 67 | ) | |
| 68 | - channel = transport_cls.create_channel(attempt_direct_path=attempt_direct_path) | ||
| 69 | - transport = transport_cls(credentials=credentials, channel=channel) | ||
| 68 | + channel = transport_cls.create_channel( | ||
| 69 | + attempt_direct_path=attempt_direct_path, credentials=credentials | ||
| 70 | + ) | ||
| 71 | + transport = transport_cls(channel=channel) | ||
| 70 | 72 | ||
| 71 | 73 | return storage_v2.StorageAsyncClient( | |
| 72 | 74 | transport=transport, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | import unittest | |
| 16 | 16 | from unittest import mock | |
| 17 | 17 | from google.auth import credentials as auth_credentials | |
| 18 | + from google.auth.credentials import AnonymousCredentials | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | 21 | def _make_credentials(spec=None): | |
@@ -38,12 +39,10 @@ def test_constructor_default_options(self, mock_async_storage_client): | |||
| 38 | 39 | "grpc_asyncio" | |
| 39 | 40 | ) | |
| 40 | 41 | mock_transport_cls.create_channel.assert_called_once_with( | |
| 41 | - attempt_direct_path=True | ||
| 42 | + attempt_direct_path=True, credentials=mock_creds | ||
| 42 | 43 | ) | |
| 43 | 44 | mock_channel = mock_transport_cls.create_channel.return_value | |
| 44 | - mock_transport_cls.assert_called_once_with( | ||
| 45 | - credentials=mock_creds, channel=mock_channel | ||
| 46 | - ) | ||
| 45 | + mock_transport_cls.assert_called_once_with(channel=mock_channel) | ||
| 47 | 46 | mock_transport = mock_transport_cls.return_value | |
| 48 | 47 | mock_async_storage_client.assert_called_once_with( | |
| 49 | 48 | transport=mock_transport, | |
@@ -64,21 +63,77 @@ def test_constructor_disables_directpath(self, mock_async_storage_client): | |||
| 64 | 63 | ) | |
| 65 | 64 | ||
| 66 | 65 | mock_transport_cls.create_channel.assert_called_once_with( | |
| 67 | - attempt_direct_path=False | ||
| 66 | + attempt_direct_path=False, credentials=mock_creds | ||
| 68 | 67 | ) | |
| 69 | 68 | mock_channel = mock_transport_cls.create_channel.return_value | |
| 70 | - mock_transport_cls.assert_called_once_with( | ||
| 71 | - credentials=mock_creds, channel=mock_channel | ||
| 72 | - ) | ||
| 69 | + mock_transport_cls.assert_called_once_with(channel=mock_channel) | ||
| 73 | 70 | ||
| 74 | 71 | @mock.patch("google.cloud._storage_v2.StorageAsyncClient") | |
| 75 | - def test_grpc_client_property(self, mock_async_storage_client): | ||
| 72 | + def test_grpc_client_property(self, mock_grpc_gapic_client): | ||
| 76 | 73 | from google.cloud.storage._experimental.asyncio import async_grpc_client | |
| 77 | 74 | ||
| 75 | + # Arrange | ||
| 76 | + mock_transport_cls = mock.MagicMock() | ||
| 77 | + mock_grpc_gapic_client.get_transport_class.return_value = mock_transport_cls | ||
| 78 | + channel_sentinel = mock.sentinel.channel | ||
| 79 | + | ||
| 80 | + mock_transport_cls.create_channel.return_value = channel_sentinel | ||
| 81 | + mock_transport_cls.return_value = mock.sentinel.transport | ||
| 82 | + | ||
| 78 | 83 | mock_creds = _make_credentials() | |
| 84 | + mock_client_info = mock.sentinel.client_info | ||
| 85 | + mock_client_options = mock.sentinel.client_options | ||
| 86 | + mock_attempt_direct_path = mock.sentinel.attempt_direct_path | ||
| 87 | + | ||
| 88 | + # Act | ||
| 89 | + client = async_grpc_client.AsyncGrpcClient( | ||
| 90 | + credentials=mock_creds, | ||
| 91 | + client_info=mock_client_info, | ||
| 92 | + client_options=mock_client_options, | ||
| 93 | + attempt_direct_path=mock_attempt_direct_path, | ||
| 94 | + ) | ||
| 95 | + | ||
| 96 | + mock_grpc_gapic_client.get_transport_class.return_value = mock_transport_cls | ||
| 97 | + | ||
| 98 | + mock_transport_cls.create_channel.return_value = channel_sentinel | ||
| 99 | + mock_transport_instance = mock.sentinel.transport | ||
| 100 | + mock_transport_cls.return_value = mock_transport_instance | ||
| 101 | + | ||
| 102 | + retrieved_client = client.grpc_client | ||
| 103 | + | ||
| 104 | + # Assert | ||
| 105 | + mock_transport_cls.create_channel.assert_called_once_with( | ||
| 106 | + attempt_direct_path=mock_attempt_direct_path, credentials=mock_creds | ||
| 107 | + ) | ||
| 108 | + mock_transport_cls.assere_with(channel=channel_sentinel) | ||
| 109 | + mock_grpc_gapic_client.assert_called_once_with( | ||
| 110 | + transport=mock_transport_instance, | ||
| 111 | + client_info=mock_client_info, | ||
| 112 | + client_options=mock_client_options, | ||
| 113 | + ) | ||
| 114 | + self.assertIs(retrieved_client, mock_grpc_gapic_client.return_value) | ||
| 79 | 115 | ||
| 80 | - client = async_grpc_client.AsyncGrpcClient(credentials=mock_creds) | ||
| 116 | + @mock.patch("google.cloud._storage_v2.StorageAsyncClient") | ||
| 117 | + def test_grpc_client_with_anon_creds(self, mock_grpc_gapic_client): | ||
| 118 | + from google.cloud.storage._experimental.asyncio import async_grpc_client | ||
| 81 | 119 | ||
| 120 | + # Arrange | ||
| 121 | + mock_transport_cls = mock.MagicMock() | ||
| 122 | + mock_grpc_gapic_client.get_transport_class.return_value = mock_transport_cls | ||
| 123 | + channel_sentinel = mock.sentinel.channel | ||
| 124 | + | ||
| 125 | + mock_transport_cls.create_channel.return_value = channel_sentinel | ||
| 126 | + mock_transport_cls.return_value = mock.sentinel.transport | ||
| 127 | + | ||
| 128 | + # Act | ||
| 129 | + anonymous_creds = AnonymousCredentials() | ||
| 130 | + client = async_grpc_client.AsyncGrpcClient(credentials=anonymous_creds) | ||
| 82 | 131 | retrieved_client = client.grpc_client | |
| 83 | 132 | ||
| 84 | - self.assertIs(retrieved_client, mock_async_storage_client.return_value) | ||
| 133 | + # Assert | ||
| 134 | + self.assertIs(retrieved_client, mock_grpc_gapic_client.return_value) | ||
| 135 | + | ||
| 136 | + mock_transport_cls.create_channel.assert_called_once_with( | ||
| 137 | + attempt_direct_path=True, credentials=anonymous_creds | ||
| 138 | + ) | ||
| 139 | + mock_transport_cls.assert_called_once_with(channel=channel_sentinel) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments