Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ filterwarnings = [
"ignore:There is no current event loop:DeprecationWarning",
# Remove after support for Python 3.7 is dropped
"ignore:After January 1, 2024, new releases of this library will drop support for Python 3.7:DeprecationWarning",
# Remove after support for Python 3.10 is dropped
"ignore:.*You are using a.* Python version \\(3\\.10:FutureWarning",
# Remove after support for Python 3.11 is dropped
"ignore:.*You are using a.* Python version \\(3\\.11:FutureWarning",
# Remove after support for Python 3.12 is dropped
"ignore:.*You are using a.* Python version \\(3\\.12:FutureWarning",
]
2 changes: 1 addition & 1 deletion tests/asyncio/gapic/test_method_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ async def test_wrap_method_with_overriding_timeout_as_a_number():
actual_timeout = method.call_args[1]["timeout"]
metadata = method.call_args[1]["metadata"]
assert metadata == mock.ANY
assert actual_timeout == pytest.approx(22, abs=0.01)
assert actual_timeout == pytest.approx(22, abs=0.05)


@pytest.mark.asyncio
Expand Down
44 changes: 30 additions & 14 deletions tests/asyncio/test_grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,15 @@ def test_create_channel_explicit_with_duplicate_credentials():
target = "example:443"

with pytest.raises(exceptions.DuplicateCredentialArgs) as excinfo:
grpc_helpers_async.create_channel(
target,
credentials_file="credentials.json",
credentials=mock.sentinel.credentials,
)
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
with pytest.warns(DeprecationWarning):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment to clarify that credentials_file is deprecated. Applies throughout

grpc_helpers_async.create_channel(
target,
credentials_file="credentials.json",
credentials=mock.sentinel.credentials,
)

assert "mutually exclusive" in str(excinfo.value)

Expand Down Expand Up @@ -641,9 +645,13 @@ def test_create_channel_with_credentials_file(
credentials_file = "/path/to/credentials/file.json"
composite_creds = composite_creds_call.return_value

channel = grpc_helpers_async.create_channel(
target, credentials_file=credentials_file
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
channel = grpc_helpers_async.create_channel(
target, credentials_file=credentials_file
)

google.auth.load_credentials_from_file.assert_called_once_with(
credentials_file, scopes=None, default_scopes=None
Expand All @@ -670,9 +678,13 @@ def test_create_channel_with_credentials_file_and_scopes(
credentials_file = "/path/to/credentials/file.json"
composite_creds = composite_creds_call.return_value

channel = grpc_helpers_async.create_channel(
target, credentials_file=credentials_file, scopes=scopes
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
channel = grpc_helpers_async.create_channel(
target, credentials_file=credentials_file, scopes=scopes
)

google.auth.load_credentials_from_file.assert_called_once_with(
credentials_file, scopes=scopes, default_scopes=None
Expand All @@ -699,9 +711,13 @@ def test_create_channel_with_credentials_file_and_default_scopes(
credentials_file = "/path/to/credentials/file.json"
composite_creds = composite_creds_call.return_value

channel = grpc_helpers_async.create_channel(
target, credentials_file=credentials_file, default_scopes=default_scopes
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
channel = grpc_helpers_async.create_channel(
target, credentials_file=credentials_file, default_scopes=default_scopes
)

google.auth.load_credentials_from_file.assert_called_once_with(
credentials_file, scopes=None, default_scopes=default_scopes
Expand Down
70 changes: 53 additions & 17 deletions tests/unit/operations_v1/test_operations_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ def test_operations_client_client_options(
)

# Check the case credentials_file is provided
options = client_options.ClientOptions(credentials_file="credentials.json")
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
options = client_options.ClientOptions(credentials_file="credentials.json")
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options, transport=transport_name)
Expand Down Expand Up @@ -539,11 +543,25 @@ def test_operations_client_client_options_credentials_file(
client_class, transport_class, transport_name
):
# Check the case credentials file is provided.
options = client_options.ClientOptions(credentials_file="credentials.json")
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
options = client_options.ClientOptions(credentials_file="credentials.json")
if "async" in str(client_class):
# TODO(): Add support for credentials file to async REST transport.
with pytest.raises(core_exceptions.AsyncRestUnsupportedParameterError):
client_class(client_options=options, transport=transport_name)
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options, transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file="credentials.json",
host=client.DEFAULT_ENDPOINT,
scopes=None,
client_cert_source_for_mtls=None,
quota_project_id=None,
client_info=transports.base.DEFAULT_CLIENT_INFO,
always_use_jwt_access=True,
)
else:
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
Expand All @@ -570,10 +588,20 @@ def test_operations_client_client_options_credentials_file(
return_value=(mock.sentinel.credentials, mock.sentinel.project),
)
def test_list_operations_rest(google_auth_default, credentials_file):
sync_transport = transports.rest.OperationsRestTransport(
credentials_file=credentials_file,
http_options=HTTP_OPTIONS,
)
if credentials_file is not None:
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
sync_transport = transports.rest.OperationsRestTransport(
credentials_file=credentials_file,
http_options=HTTP_OPTIONS,
)
else:
sync_transport = transports.rest.OperationsRestTransport(
credentials_file=credentials_file,
http_options=HTTP_OPTIONS,
)

client = AbstractOperationsClient(transport=sync_transport)

Expand Down Expand Up @@ -1130,10 +1158,14 @@ def test_transport_adc(client_class, transport_class, credentials):
def test_operations_base_transport_error():
# Passing both a credentials object and credentials_file should raise an error
with pytest.raises(core_exceptions.DuplicateCredentialArgs):
transports.OperationsTransport(
credentials=ga_credentials.AnonymousCredentials(),
credentials_file="credentials.json",
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
transports.OperationsTransport(
credentials=ga_credentials.AnonymousCredentials(),
credentials_file="credentials.json",
)


def test_operations_base_transport():
Expand Down Expand Up @@ -1171,10 +1203,14 @@ def test_operations_base_transport_with_credentials_file():
) as Transport:
Transport.return_value = None
load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
transports.OperationsTransport(
credentials_file="credentials.json",
quota_project_id="octopus",
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
transports.OperationsTransport(
credentials_file="credentials.json",
quota_project_id="octopus",
)
load_creds.assert_called_once_with(
"credentials.json",
scopes=None,
Expand Down
41 changes: 24 additions & 17 deletions tests/unit/test_client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ def get_client_encrypted_cert():


def test_constructor():

options = client_options.ClientOptions(
api_endpoint="foo.googleapis.com",
client_cert_source=get_client_cert,
quota_project_id="quote-proj",
credentials_file="path/to/credentials.json",
scopes=[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
api_audience="foo2.googleapis.com",
universe_domain="googleapis.com",
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
options = client_options.ClientOptions(
api_endpoint="foo.googleapis.com",
client_cert_source=get_client_cert,
quota_project_id="quote-proj",
credentials_file="path/to/credentials.json",
scopes=[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
],
api_audience="foo2.googleapis.com",
universe_domain="googleapis.com",
)

assert options.api_endpoint == "foo.googleapis.com"
assert options.client_cert_source() == (b"cert", b"key")
Expand Down Expand Up @@ -102,10 +105,14 @@ def test_constructor_with_api_key():

def test_constructor_with_both_api_key_and_credentials_file():
with pytest.raises(ValueError):
client_options.ClientOptions(
api_key="api-key",
credentials_file="path/to/credentials.json",
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
client_options.ClientOptions(
api_key="api-key",
credentials_file="path/to/credentials.json",
)


def test_from_dict():
Expand Down
40 changes: 28 additions & 12 deletions tests/unit/test_grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,15 @@ def test_create_channel_explicit_with_duplicate_credentials():
target = "example.com:443"

with pytest.raises(exceptions.DuplicateCredentialArgs):
grpc_helpers.create_channel(
target,
credentials_file="credentials.json",
credentials=mock.sentinel.credentials,
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
grpc_helpers.create_channel(
target,
credentials_file="credentials.json",
credentials=mock.sentinel.credentials,
)


@mock.patch("grpc.compute_engine_channel_credentials")
Expand Down Expand Up @@ -710,7 +714,11 @@ def test_create_channel_with_credentials_file(
credentials_file = "/path/to/credentials/file.json"
composite_creds = composite_creds_call.return_value

channel = grpc_helpers.create_channel(target, credentials_file=credentials_file)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
channel = grpc_helpers.create_channel(target, credentials_file=credentials_file)

google.auth.load_credentials_from_file.assert_called_once_with(
credentials_file, scopes=None, default_scopes=None
Expand Down Expand Up @@ -742,9 +750,13 @@ def test_create_channel_with_credentials_file_and_scopes(
credentials_file = "/path/to/credentials/file.json"
composite_creds = composite_creds_call.return_value

channel = grpc_helpers.create_channel(
target, credentials_file=credentials_file, scopes=scopes
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
channel = grpc_helpers.create_channel(
target, credentials_file=credentials_file, scopes=scopes
)

google.auth.load_credentials_from_file.assert_called_once_with(
credentials_file, scopes=scopes, default_scopes=None
Expand Down Expand Up @@ -776,9 +788,13 @@ def test_create_channel_with_credentials_file_and_default_scopes(
credentials_file = "/path/to/credentials/file.json"
composite_creds = composite_creds_call.return_value

channel = grpc_helpers.create_channel(
target, credentials_file=credentials_file, default_scopes=default_scopes
)
with pytest.warns(DeprecationWarning):
# The `credentials_file` argument is deprecated by
# the Google Cloud Auth library (`google-auth`), which is the
# upstream dependency responsible for handling authentication.
channel = grpc_helpers.create_channel(
target, credentials_file=credentials_file, default_scopes=default_scopes
)

load_credentials_from_file.assert_called_once_with(
credentials_file, scopes=None, default_scopes=default_scopes
Expand Down
Loading