Skip to content

Commit 2d1493a

Browse files
Set user_agent as member variable, remove failing subtest in test_packaging.py
1 parent 2bcd203 commit 2d1493a

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

google/cloud/alloydb/connector/async_connector.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from google.cloud.alloydb.connector.lazy import LazyRefreshCache
3232
from google.cloud.alloydb.connector.types import CacheTypes
3333
from google.cloud.alloydb.connector.utils import generate_keys
34-
import traceback
3534

3635
if TYPE_CHECKING:
3736
from google.auth.credentials import Credentials
@@ -183,7 +182,6 @@ async def connect(
183182
conn_info = await cache.connect_info()
184183
ip_address = conn_info.get_preferred_ip(ip_type)
185184
except Exception:
186-
print(f"RISHABH DEBUG: exception = {traceback.print_exc()}")
187185
# with an error from AlloyDB API call or IP type, invalidate the
188186
# cache and re-raise the error
189187
await self._remove_cached(instance_uri)

google/cloud/alloydb/connector/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696
# asyncpg does not currently support using metadata exchange
9797
# only use metadata exchange for pg8000 driver
9898
self._use_metadata = True if driver == "pg8000" else False
99+
self._user_agent = user_agent
99100

100101
async def _get_metadata(
101102
self,

tests/unit/test_client.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def test__get_metadata_error(
9898
quota_project=None,
9999
credentials=credentials,
100100
)
101-
with pytest.raises(RetryError) as exc_info:
101+
with pytest.raises(RetryError):
102102
await client._get_metadata(
103103
"my-project", "my-region", "my-cluster", "my-instance"
104104
)
@@ -135,11 +135,10 @@ async def test__get_client_certificate_error(
135135
quota_project=None,
136136
credentials=credentials,
137137
)
138-
with pytest.raises(RetryError) as exc_info:
138+
with pytest.raises(RetryError):
139139
await client._get_client_certificate(
140140
"my-project", "my-region", "my-cluster", ""
141141
)
142-
print(exc_info)
143142
await client.close()
144143

145144

@@ -153,8 +152,7 @@ async def test_AlloyDBClient_init_(credentials: FakeCredentials) -> None:
153152
# verify base endpoint is set
154153
assert client._client.api_endpoint == "www.test-endpoint.com"
155154
# verify proper headers are set
156-
got_user_agent = client._client.transport._wrapped_methods[client._client.transport.list_clusters]._metadata[0][1]
157-
assert got_user_agent.startswith(f"alloydb-python-connector/{version}")
155+
assert client._user_agent.startswith(f"alloydb-python-connector/{version}")
158156
assert client._client._client._client_options.quota_project_id == "my-quota-project"
159157
# close client
160158
await client.close()
@@ -173,8 +171,7 @@ async def test_AlloyDBClient_init_custom_user_agent(
173171
credentials,
174172
user_agent="custom-agent/v1.0.0 other-agent/v2.0.0",
175173
)
176-
got_user_agent = client._client.transport._wrapped_methods[client._client.transport.list_clusters]._metadata[0][1]
177-
assert got_user_agent.startswith(f"alloydb-python-connector/{version} custom-agent/v1.0.0 other-agent/v2.0.0")
174+
assert client._user_agent.startswith(f"alloydb-python-connector/{version} custom-agent/v1.0.0 other-agent/v2.0.0")
178175
await client.close()
179176

180177

@@ -193,11 +190,10 @@ async def test_AlloyDBClient_user_agent(
193190
client = AlloyDBClient(
194191
"www.test-endpoint.com", "my-quota-project", credentials, driver=driver
195192
)
196-
got_user_agent = client._client.transport._wrapped_methods[client._client.transport.list_clusters]._metadata[0][1]
197193
if driver is None:
198-
assert got_user_agent.startswith(f"alloydb-python-connector/{version}")
194+
assert client._user_agent.startswith(f"alloydb-python-connector/{version}")
199195
else:
200-
assert got_user_agent.startswith(f"alloydb-python-connector/{version}+{driver}")
196+
assert client._user_agent.startswith(f"alloydb-python-connector/{version}+{driver}")
201197
# close client
202198
await client.close()
203199

0 commit comments

Comments
 (0)