Skip to content

Commit 197816e

Browse files
fix lint errors
1 parent 97521e8 commit 197816e

File tree

6 files changed

+50
-38
lines changed

6 files changed

+50
-38
lines changed

google/cloud/alloydb/connector/client.py

+23-17
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
from google.api_core.gapic_v1.client_info import ClientInfo
2424
from google.auth.credentials import TokenState
2525
from google.auth.transport import requests
26+
import google.cloud.alloydb_v1beta as v1beta
27+
from google.protobuf import duration_pb2
2628

27-
from google.cloud import alloydb_v1beta
2829
from google.cloud.alloydb.connector.connection_info import ConnectionInfo
2930
from google.cloud.alloydb.connector.version import __version__ as version
30-
from google.protobuf import duration_pb2
3131

3232
if TYPE_CHECKING:
3333
from google.auth.credentials import Credentials
@@ -58,7 +58,7 @@ def __init__(
5858
alloydb_api_endpoint: str,
5959
quota_project: Optional[str],
6060
credentials: Credentials,
61-
client: Optional[alloydb_v1beta.AlloyDBAdminAsyncClient] = None,
61+
client: Optional[v1beta.AlloyDBAdminAsyncClient] = None,
6262
driver: Optional[str] = None,
6363
user_agent: Optional[str] = None,
6464
) -> None:
@@ -75,22 +75,26 @@ def __init__(
7575
A credentials object created from the google-auth Python library.
7676
Must have the AlloyDB Admin scopes. For more info check out
7777
https://google-auth.readthedocs.io/en/latest/.
78-
client (alloydb_v1beta.AlloyDBAdminAsyncClient): Async client used to
79-
make requests to AlloyDB APIs.
78+
client (v1beta.AlloyDBAdminAsyncClient): Async client used to make
79+
requests to AlloyDB APIs.
8080
Optional, defaults to None and creates new client.
8181
driver (str): Database driver to be used by the client.
8282
"""
8383
user_agent = _format_user_agent(driver, user_agent)
8484

85-
self._client = client if client else alloydb_v1beta.AlloyDBAdminAsyncClient(
86-
credentials=credentials,
87-
client_options=ClientOptions(
88-
api_endpoint=alloydb_api_endpoint,
89-
quota_project_id=quota_project,
90-
),
91-
client_info=ClientInfo(
92-
user_agent=user_agent,
93-
),
85+
self._client = (
86+
client
87+
if client
88+
else v1beta.AlloyDBAdminAsyncClient(
89+
credentials=credentials,
90+
client_options=ClientOptions(
91+
api_endpoint=alloydb_api_endpoint,
92+
quota_project_id=quota_project,
93+
),
94+
client_info=ClientInfo(
95+
user_agent=user_agent,
96+
),
97+
)
9498
)
9599
self._credentials = credentials
96100
# asyncpg does not currently support using metadata exchange
@@ -122,9 +126,11 @@ async def _get_metadata(
122126
Returns:
123127
dict: IP addresses of the AlloyDB instance.
124128
"""
125-
parent = f"projects/{project}/locations/{region}/clusters/{cluster}/instances/{name}"
129+
parent = (
130+
f"projects/{project}/locations/{region}/clusters/{cluster}/instances/{name}"
131+
)
126132

127-
req = alloydb_v1beta.GetConnectionInfoRequest(parent=parent)
133+
req = v1beta.GetConnectionInfoRequest(parent=parent)
128134
resp = await self._client.get_connection_info(request=req)
129135

130136
# Remove trailing period from PSC DNS name.
@@ -166,7 +172,7 @@ async def _get_client_certificate(
166172
parent = f"projects/{project}/locations/{region}/clusters/{cluster}"
167173
dur = duration_pb2.Duration()
168174
dur.seconds = 3600
169-
req = alloydb_v1beta.GenerateClientCertificateRequest(
175+
req = v1beta.GenerateClientCertificateRequest(
170176
parent=parent,
171177
cert_duration=dur,
172178
public_key=pub_key,

mypy.ini

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ ignore_missing_imports = True
1111

1212
[mypy-asyncpg]
1313
ignore_missing_imports = True
14+
15+
[mypy-google.cloud.alloydb_v1beta]
16+
ignore_missing_imports = True
17+
18+
[mypy-google.api_core.*]
19+
ignore_missing_imports = True

tests/unit/mocks.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ def write_static_info(i: FakeInstance) -> io.StringIO:
452452

453453

454454
class FakeAlloyDBAdminAsyncClient:
455-
async def get_connection_info(self, request: alloydb_v1beta.GetConnectionInfoRequest) -> alloydb_v1beta.types.resources.ConnectionInfo:
455+
async def get_connection_info(
456+
self, request: alloydb_v1beta.GetConnectionInfoRequest
457+
) -> alloydb_v1beta.types.resources.ConnectionInfo:
456458
ci = alloydb_v1beta.types.resources.ConnectionInfo()
457459
ci.ip_address = "10.0.0.1"
458460
ci.public_ip_address = "127.0.0.1"
@@ -473,7 +475,9 @@ async def get_connection_info(self, request: alloydb_v1beta.GetConnectionInfoReq
473475
ci.public_ip_address = ""
474476
return ci
475477

476-
async def generate_client_certificate(self, request: alloydb_v1beta.GenerateClientCertificateRequest) -> alloydb_v1beta.types.service.GenerateClientCertificateResponse:
478+
async def generate_client_certificate(
479+
self, request: alloydb_v1beta.GenerateClientCertificateRequest
480+
) -> alloydb_v1beta.types.service.GenerateClientCertificateResponse:
477481
ccr = alloydb_v1beta.types.service.GenerateClientCertificateResponse()
478482
ccr.ca_cert = "This is the CA cert"
479483
ccr.pem_certificate_chain.append("This is the client cert")

tests/unit/test_async_connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import asyncio
1616
from typing import Union
1717

18+
from google.api_core.exceptions import RetryError
1819
from mock import patch
1920
from mocks import FakeAlloyDBClient
2021
from mocks import FakeConnectionInfo
2122
from mocks import FakeCredentials
2223
import pytest
2324

24-
from google.api_core.exceptions import RetryError
2525
from google.cloud.alloydb.connector import AsyncConnector
2626
from google.cloud.alloydb.connector import IPTypes
2727
from google.cloud.alloydb.connector.exceptions import IPTypeNotFoundError

tests/unit/test_client.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Optional
15+
from typing import Optional
1616

17-
from aiohttp import ClientResponseError
18-
from aioresponses import aioresponses
19-
from mocks import FakeAlloyDBAdminAsyncClient, FakeCredentials
17+
from google.api_core.exceptions import RetryError
18+
from mocks import FakeAlloyDBAdminAsyncClient
19+
from mocks import FakeCredentials
2020
import pytest
2121

22-
from google.api_core.exceptions import RetryError
23-
from google.cloud import alloydb_v1beta
2422
from google.cloud.alloydb.connector.client import AlloyDBClient
2523
from google.cloud.alloydb.connector.utils import generate_keys
2624
from google.cloud.alloydb.connector.version import __version__ as version
@@ -46,9 +44,7 @@ async def test__get_metadata(credentials: FakeCredentials) -> None:
4644

4745

4846
@pytest.mark.asyncio
49-
async def test__get_metadata_with_public_ip(
50-
credentials: FakeCredentials
51-
) -> None:
47+
async def test__get_metadata_with_public_ip(credentials: FakeCredentials) -> None:
5248
"""
5349
Test _get_metadata returns successfully with Public IP.
5450
"""
@@ -67,9 +63,7 @@ async def test__get_metadata_with_public_ip(
6763

6864

6965
@pytest.mark.asyncio
70-
async def test__get_metadata_with_psc(
71-
credentials: FakeCredentials
72-
) -> None:
66+
async def test__get_metadata_with_psc(credentials: FakeCredentials) -> None:
7367
"""
7468
Test _get_metadata returns successfully with PSC DNS name.
7569
"""
@@ -106,9 +100,7 @@ async def test__get_metadata_error(
106100

107101

108102
@pytest.mark.asyncio
109-
async def test__get_client_certificate(
110-
credentials: FakeCredentials
111-
) -> None:
103+
async def test__get_client_certificate(credentials: FakeCredentials) -> None:
112104
"""
113105
Test _get_client_certificate returns successfully.
114106
"""
@@ -171,7 +163,9 @@ async def test_AlloyDBClient_init_custom_user_agent(
171163
credentials,
172164
user_agent="custom-agent/v1.0.0 other-agent/v2.0.0",
173165
)
174-
assert client._user_agent.startswith(f"alloydb-python-connector/{version} custom-agent/v1.0.0 other-agent/v2.0.0")
166+
assert client._user_agent.startswith(
167+
f"alloydb-python-connector/{version} custom-agent/v1.0.0 other-agent/v2.0.0"
168+
)
175169
await client.close()
176170

177171

@@ -193,7 +187,9 @@ async def test_AlloyDBClient_user_agent(
193187
if driver is None:
194188
assert client._user_agent.startswith(f"alloydb-python-connector/{version}")
195189
else:
196-
assert client._user_agent.startswith(f"alloydb-python-connector/{version}+{driver}")
190+
assert client._user_agent.startswith(
191+
f"alloydb-python-connector/{version}+{driver}"
192+
)
197193
# close client
198194
await client.close()
199195

tests/unit/test_connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
from threading import Thread
1717
from typing import Union
1818

19+
from google.api_core.exceptions import RetryError
1920
from mock import patch
2021
from mocks import FakeAlloyDBClient
2122
from mocks import FakeCredentials
2223
from mocks import write_static_info
2324
import pytest
2425

25-
from google.api_core.exceptions import RetryError
2626
from google.cloud.alloydb.connector import Connector
2727
from google.cloud.alloydb.connector import IPTypes
2828
from google.cloud.alloydb.connector.exceptions import IPTypeNotFoundError

0 commit comments

Comments
 (0)