Skip to content

Commit

Permalink
chore: remove unreachable code (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon authored Feb 1, 2024
1 parent 18bc377 commit 25a740a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 85 deletions.
11 changes: 0 additions & 11 deletions google/cloud/sql/connector/refresh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ async def _get_metadata(
:raises TypeError: If any of the arguments are not the specified type.
"""

if not isinstance(project, str):
raise TypeError(f"project must be of type str, got {type(project)}")
if not isinstance(region, str):
raise TypeError(f"region must be of type str, got {type(region)}")
if not isinstance(instance, str):
raise TypeError(f"instance must be of type str, got {type(instance)}")

if not credentials.valid:
request = google.auth.transport.requests.Request()
credentials.refresh(request)
Expand Down Expand Up @@ -167,10 +160,6 @@ async def _get_ephemeral(

logger.debug(f"['{instance}']: Requesting ephemeral certificate")

if not isinstance(project, str):
raise TypeError(f"project must be of type str, got {type(project)}")
if not isinstance(instance, str):
raise TypeError(f"instance must be of type str, got {type(instance)}")
if not isinstance(pub_key, str):
raise TypeError(f"pub_key must be of type str, got {type(pub_key)}")

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ def generate_ephemeral(self, client_bytes: str) -> str:
client_bytes.encode("UTF-8"), default_backend()
) # type: ignore
ephemeral_cert = client_key_signed_cert(self.cert, self.key, client_key)
print(
"Test generate time: ",
datetime.datetime.utcnow() + datetime.timedelta(minutes=10),
)
return json.dumps(
{
"ephemeralCert": {
Expand Down
72 changes: 2 additions & 70 deletions tests/unit/test_refresh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,38 +93,14 @@ async def test_get_ephemeral_TypeError(credentials: Credentials) -> None:
when given incorrect input arg types.
"""
client_session = Mock(aiohttp.ClientSession)
project = "my-project"
instance = "my-instance"
pub_key = "key"

# incorrect project type
with pytest.raises(TypeError):
await _get_ephemeral(
client_session=client_session,
sqladmin_api_endpoint="https://sqladmin.googleapis.com",
credentials=credentials,
project=12345,
instance=instance,
pub_key=pub_key,
)
# incorrect instance type
with pytest.raises(TypeError):
await _get_ephemeral(
client_session=client_session,
sqladmin_api_endpoint="https://sqladmin.googleapis.com",
credentials=credentials,
project=project,
instance=12345,
pub_key=pub_key,
)
# incorrect pub_key type
with pytest.raises(TypeError):
await _get_ephemeral(
client_session=client_session,
sqladmin_api_endpoint="https://sqladmin.googleapis.com",
credentials=credentials,
project=project,
instance=instance,
project="my-project",
instance="my-instance",
pub_key=12345,
)

Expand Down Expand Up @@ -166,50 +142,6 @@ async def test_get_metadata(
)


@pytest.mark.asyncio
@no_type_check
async def test_get_metadata_TypeError(credentials: Credentials) -> None:
"""
Test to check whether _get_metadata throws proper TypeError
when given incorrect input arg types.
"""
client_session = Mock(aiohttp.ClientSession)
project = "my-project"
region = "my-region"
instance = "my-instance"

# incorrect project type
with pytest.raises(TypeError):
await _get_metadata(
client_session=client_session,
sqladmin_api_endpoint="https://sqladmin.googleapis.com",
credentials=credentials,
project=12345,
region=region,
instance=instance,
)
# incorrect region type
with pytest.raises(TypeError):
await _get_metadata(
client_session=client_session,
sqladmin_api_endpoint="https://sqladmin.googleapis.com",
credentials=credentials,
project=project,
region=1,
instance=instance,
)
# incorrect instance type
with pytest.raises(TypeError):
await _get_metadata(
client_session=client_session,
sqladmin_api_endpoint="https://sqladmin.googleapis.com",
credentials=credentials,
project=project,
region=region,
instance=12345,
)


@pytest.mark.asyncio
@no_type_check
async def test_get_metadata_region_mismatch(
Expand Down

0 comments on commit 25a740a

Please sign in to comment.