|
19 | 19 | import pytest |
20 | 20 | from google.api_core.gapic_v1 import client_info |
21 | 21 | from google.auth import credentials |
22 | | - |
23 | 22 | from google.cloud.bigquery_storage_v1 import types |
24 | 23 |
|
25 | 24 | PROJECT = "my-project" |
@@ -158,24 +157,15 @@ def test_read_rows(mock_transport, client_under_test): |
158 | 157 | ["google.cloud.bigquery_storage_v1", "google.cloud.bigquery_storage_v1beta2"], |
159 | 158 | ) |
160 | 159 | def test_init_default_client_info(module_under_test): |
161 | | - from google.api_core.gapic_v1.client_info import METRICS_METADATA_KEY |
162 | | - |
163 | 160 | mut = importlib.import_module(module_under_test) |
164 | | - |
165 | 161 | creds = mock.Mock(spec=credentials.Credentials) |
166 | | - client = mut.BigQueryWriteClient(credentials=creds) |
| 162 | + expected_client_info = f"gccl/{mut.__version__}" |
167 | 163 |
|
168 | | - installed_version = mut.__version__ |
169 | | - expected_client_info = f"gccl/{installed_version}" |
| 164 | + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as mock_wrap: |
| 165 | + mut.BigQueryWriteClient(credentials=creds) |
170 | 166 |
|
171 | | - for wrapped_method in client.transport._wrapped_methods.values(): |
172 | | - user_agent = next( |
173 | | - ( |
174 | | - header_value |
175 | | - for header, header_value in wrapped_method._metadata |
176 | | - if header == METRICS_METADATA_KEY |
177 | | - ), |
178 | | - None, |
179 | | - ) |
180 | | - assert user_agent is not None |
181 | | - assert expected_client_info in user_agent |
| 167 | + assert mock_wrap.call_count > 0 |
| 168 | + for call in mock_wrap.call_args_list: |
| 169 | + client_info = call.kwargs.get("client_info") |
| 170 | + assert client_info is not None |
| 171 | + assert expected_client_info in client_info.to_user_agent() |
0 commit comments