Skip to content

Commit

Permalink
Fix lint errors using black
Browse files Browse the repository at this point in the history
  • Loading branch information
rhatgadkar-goog committed Nov 14, 2024
1 parent a1ce813 commit 866b8e2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
4 changes: 1 addition & 3 deletions google/cloud/alloydb/connector/async_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ async def _remove_cached(self, instance_uri: str) -> None:
"""Stops all background refreshes and deletes the connection
info cache from the map of caches.
"""
logger.debug(
f"['{instance_uri}']: Removing connection info from cache"
)
logger.debug(f"['{instance_uri}']: Removing connection info from cache")
# remove cache from stored caches and close it
cache = self._cache.pop(instance_uri)
await cache.close()
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/alloydb/connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ async def _remove_cached(self, instance_uri: str) -> None:
"""Stops all background refreshes and deletes the connection
info cache from the map of caches.
"""
logger.debug(
f"['{instance_uri}']: Removing connection info from cache"
)
logger.debug(f"['{instance_uri}']: Removing connection info from cache")
# remove cache from stored caches and close it
cache = self._cache.pop(instance_uri)
await cache.close()
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,16 @@ def __init__(

i = FakeInstance()
# The instances that currently exist and the client can send API requests to.
self.existing_instances = [f"projects/{i.project}/locations/{i.region}/clusters/{i.cluster}/instances/{i.name}"]
self.existing_instances = [
f"projects/{i.project}/locations/{i.region}/clusters/{i.cluster}/instances/{i.name}"
]

async def _get_metadata(self, *args: Any, **kwargs: Any) -> str:
instance_uri = f"projects/{self.instance.project}/locations/{self.instance.region}/clusters/{self.instance.cluster}/instances/{self.instance.name}"
if instance_uri not in self.existing_instances:
raise ClientResponseError(RequestInfo(url = instance_uri, method = "GET", headers = None), 404)
raise ClientResponseError(
RequestInfo(url=instance_uri, method="GET", headers=None), 404
)
return self.instance.ip_addrs

async def _get_client_certificate(
Expand All @@ -227,7 +231,9 @@ async def _get_client_certificate(
) -> Tuple[str, List[str]]:
instance_uri = f"projects/{self.instance.project}/locations/{self.instance.region}/clusters/{self.instance.cluster}/instances/{self.instance.name}"
if instance_uri not in self.existing_instances:
raise ClientResponseError(RequestInfo(url = instance_uri, method = "POST", headers = None), 404)
raise ClientResponseError(
RequestInfo(url=instance_uri, method="POST", headers=None), 404
)
root_cert, intermediate_cert, server_cert = self.instance.get_pem_certs()
# encode public key to bytes
pub_key_bytes: rsa.RSAPublicKey = serialization.load_pem_public_key(
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/test_async_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,20 @@ async def test_async_connect_bad_ip_type(
== f"Incorrect value for ip_type, got '{bad_ip_type}'. Want one of: 'PUBLIC', 'PRIVATE', 'PSC'."
)

async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials) -> None:

async def test_Connector_remove_cached_bad_instance(
credentials: FakeCredentials,
) -> None:
"""When a Connector attempts to retrieve connection info for a
non-existent instance, it should delete the instance from
the cache and ensure no background refresh happens (which would be
wasted cycles).
"""
instance_uri = "projects/test-project/locations/test-region/clusters/test-cluster/instances/bad-test-instance"
async with AsyncConnector(credentials=credentials) as connector:
connector._client = FakeAlloyDBClient(instance = FakeInstance(name = "bad-test-instance"))
connector._client = FakeAlloyDBClient(
instance=FakeInstance(name="bad-test-instance")
)
cache = RefreshAheadCache(instance_uri, connector._client, connector._keys)
connector._cache[instance_uri] = cache
with pytest.raises(ClientResponseError):
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,19 @@ def test_Connector_close_called_multiple_times(credentials: FakeCredentials) ->
connector.close()


async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials) -> None:
async def test_Connector_remove_cached_bad_instance(
credentials: FakeCredentials,
) -> None:
"""When a Connector attempts to retrieve connection info for a
non-existent instance, it should delete the instance from
the cache and ensure no background refresh happens (which would be
wasted cycles).
"""
instance_uri = "projects/test-project/locations/test-region/clusters/test-cluster/instances/bad-test-instance"
with Connector(credentials) as connector:
connector._client = FakeAlloyDBClient(instance = FakeInstance(name = "bad-test-instance"))
connector._client = FakeAlloyDBClient(
instance=FakeInstance(name="bad-test-instance")
)
cache = RefreshAheadCache(instance_uri, connector._client, connector._keys)
connector._cache[instance_uri] = cache
with pytest.raises(ClientResponseError):
Expand Down Expand Up @@ -249,4 +253,4 @@ async def test_Connector_remove_cached_no_ip_type(
with pytest.raises(IPTypeNotFoundError):
await connector.connect_async(instance_uri, "pg8000", ip_type="private")
# check that cache has been removed from dict
assert instance_uri not in connector._cache
assert instance_uri not in connector._cache

0 comments on commit 866b8e2

Please sign in to comment.