Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
chore: use gapic-generator-python 0.53.4 (#161)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

docs: list oneofs in docstring
fix(deps): require google-api-core >= 1.28.0
fix(deps): drop packaging dependency

committer: busunkim96@
PiperOrigin-RevId: 406468269

Source-Link: googleapis/googleapis@83d81b0

Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9
  • Loading branch information
gcf-owl-bot[bot] authored Nov 1, 2021
1 parent c331077 commit be96ebc
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 458 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#
import abc
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
import packaging.version
import pkg_resources

import google.auth # type: ignore
Expand All @@ -37,15 +36,6 @@
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()

try:
# google.auth.__version__ was added in 1.26.0
_GOOGLE_AUTH_VERSION = google.auth.__version__
except AttributeError:
try: # try pkg_resources if it is available
_GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version
except pkg_resources.DistributionNotFound: # pragma: NO COVER
_GOOGLE_AUTH_VERSION = None


class AnalyticsAdminServiceTransport(abc.ABC):
"""Abstract transport class for AnalyticsAdminService."""
Expand Down Expand Up @@ -100,7 +90,7 @@ def __init__(
host += ":443"
self._host = host

scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}

# Save the scopes.
self._scopes = scopes
Expand Down Expand Up @@ -133,29 +123,6 @@ def __init__(
# Save the credentials.
self._credentials = credentials

# TODO(busunkim): This method is in the base transport
# to avoid duplicating code across the transport classes. These functions
# should be deleted once the minimum required versions of google-auth is increased.

# TODO: Remove this function once google-auth >= 1.25.0 is required
@classmethod
def _get_scopes_kwargs(
cls, host: str, scopes: Optional[Sequence[str]]
) -> Dict[str, Optional[Sequence[str]]]:
"""Returns scopes kwargs to pass to google-auth methods depending on the google-auth version"""

scopes_kwargs = {}

if _GOOGLE_AUTH_VERSION and (
packaging.version.parse(_GOOGLE_AUTH_VERSION)
>= packaging.version.parse("1.25.0")
):
scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES}
else:
scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES}

return scopes_kwargs

def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
self._wrapped_methods = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from google.api_core import grpc_helpers_async # type: ignore
from google.auth import credentials as ga_credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
import packaging.version

import grpc # type: ignore
from grpc.experimental import aio # type: ignore
Expand Down
22 changes: 22 additions & 0 deletions google/analytics/admin_v1alpha/types/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,53 +800,75 @@ class ChangeHistoryResource(proto.Message):
r"""A snapshot of a resource as before or after the result of a
change in change history.
This message has `oneof`_ fields (mutually exclusive fields).
For each oneof, at most one member field can be set at the same time.
Setting any member of the oneof automatically clears all other
members.
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
Attributes:
account (google.analytics.admin_v1alpha.types.Account):
A snapshot of an Account resource in change
history.
This field is a member of `oneof`_ ``resource``.
property (google.analytics.admin_v1alpha.types.Property):
A snapshot of a Property resource in change
history.
This field is a member of `oneof`_ ``resource``.
web_data_stream (google.analytics.admin_v1alpha.types.WebDataStream):
A snapshot of a WebDataStream resource in
change history.
This field is a member of `oneof`_ ``resource``.
android_app_data_stream (google.analytics.admin_v1alpha.types.AndroidAppDataStream):
A snapshot of an AndroidAppDataStream
resource in change history.
This field is a member of `oneof`_ ``resource``.
ios_app_data_stream (google.analytics.admin_v1alpha.types.IosAppDataStream):
A snapshot of an IosAppDataStream resource in
change history.
This field is a member of `oneof`_ ``resource``.
firebase_link (google.analytics.admin_v1alpha.types.FirebaseLink):
A snapshot of a FirebaseLink resource in
change history.
This field is a member of `oneof`_ ``resource``.
google_ads_link (google.analytics.admin_v1alpha.types.GoogleAdsLink):
A snapshot of a GoogleAdsLink resource in
change history.
This field is a member of `oneof`_ ``resource``.
google_signals_settings (google.analytics.admin_v1alpha.types.GoogleSignalsSettings):
A snapshot of a GoogleSignalsSettings
resource in change history.
This field is a member of `oneof`_ ``resource``.
display_video_360_advertiser_link (google.analytics.admin_v1alpha.types.DisplayVideo360AdvertiserLink):
A snapshot of a DisplayVideo360AdvertiserLink
resource in change history.
This field is a member of `oneof`_ ``resource``.
display_video_360_advertiser_link_proposal (google.analytics.admin_v1alpha.types.DisplayVideo360AdvertiserLinkProposal):
A snapshot of a
DisplayVideo360AdvertiserLinkProposal resource
in change history.
This field is a member of `oneof`_ ``resource``.
conversion_event (google.analytics.admin_v1alpha.types.ConversionEvent):
A snapshot of a ConversionEvent resource in
change history.
This field is a member of `oneof`_ ``resource``.
measurement_protocol_secret (google.analytics.admin_v1alpha.types.MeasurementProtocolSecret):
A snapshot of a MeasurementProtocolSecret
resource in change history.
This field is a member of `oneof`_ ``resource``.
custom_dimension (google.analytics.admin_v1alpha.types.CustomDimension):
A snapshot of a CustomDimension resource in
change history.
This field is a member of `oneof`_ ``resource``.
custom_metric (google.analytics.admin_v1alpha.types.CustomMetric):
A snapshot of a CustomMetric resource in
change history.
This field is a member of `oneof`_ ``resource``.
data_retention_settings (google.analytics.admin_v1alpha.types.DataRetentionSettings):
A snapshot of a data retention settings
resource in change history.
This field is a member of `oneof`_ ``resource``.
"""

account = proto.Field(
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
# Until this issue is closed
# https://github.com/googleapis/google-cloud-python/issues/10566
"google-api-core[grpc] >= 1.26.0, <3.0.0dev",
"google-api-core[grpc] >= 1.28.0, <3.0.0dev",
"proto-plus >= 1.4.0",
"packaging >= 14.3",
),
python_requires=">=3.6",
classifiers=[
Expand Down
4 changes: 1 addition & 3 deletions testing/constraints-3.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
#
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
# Then this file should have foo==1.14.0
google-api-core==1.26.0
google-api-core==1.28.0
proto-plus==1.4.0
packaging==14.3
google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is required through google-api-core
106 changes: 9 additions & 97 deletions tests/unit/gapic/admin_v1alpha/test_analytics_admin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#
import os
import mock
import packaging.version

import grpc
from grpc.experimental import aio
Expand All @@ -32,9 +31,6 @@
)
from google.analytics.admin_v1alpha.services.analytics_admin_service import pagers
from google.analytics.admin_v1alpha.services.analytics_admin_service import transports
from google.analytics.admin_v1alpha.services.analytics_admin_service.transports.base import (
_GOOGLE_AUTH_VERSION,
)
from google.analytics.admin_v1alpha.types import analytics_admin
from google.analytics.admin_v1alpha.types import resources
from google.api_core import client_options
Expand All @@ -52,20 +48,6 @@
import google.auth


# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively
# through google-api-core:
# - Delete the auth "less than" test cases
# - Delete these pytest markers (Make the "greater than or equal to" tests the default).
requires_google_auth_lt_1_25_0 = pytest.mark.skipif(
packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"),
reason="This test requires google-auth < 1.25.0",
)
requires_google_auth_gte_1_25_0 = pytest.mark.skipif(
packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"),
reason="This test requires google-auth >= 1.25.0",
)


def client_cert_source_callback():
return b"cert bytes", b"key bytes"

Expand Down Expand Up @@ -227,7 +209,7 @@ def test_analytics_admin_service_client_client_options(
options = client_options.ClientOptions(api_endpoint="squid.clam.whelk")
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand All @@ -244,7 +226,7 @@ def test_analytics_admin_service_client_client_options(
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand All @@ -261,7 +243,7 @@ def test_analytics_admin_service_client_client_options(
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -290,7 +272,7 @@ def test_analytics_admin_service_client_client_options(
options = client_options.ClientOptions(quota_project_id="octopus")
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -359,7 +341,7 @@ def test_analytics_admin_service_client_mtls_env_auto(
)
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)

if use_client_cert_env == "false":
expected_client_cert_source = None
Expand Down Expand Up @@ -401,7 +383,7 @@ def test_analytics_admin_service_client_mtls_env_auto(
expected_client_cert_source = client_cert_source_callback

patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand All @@ -423,7 +405,7 @@ def test_analytics_admin_service_client_mtls_env_auto(
return_value=False,
):
patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -458,7 +440,7 @@ def test_analytics_admin_service_client_client_options_scopes(
options = client_options.ClientOptions(scopes=["1", "2"],)
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -493,7 +475,7 @@ def test_analytics_admin_service_client_client_options_credentials_file(
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)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file="credentials.json",
Expand Down Expand Up @@ -21442,7 +21424,6 @@ def test_analytics_admin_service_base_transport():
transport.close()


@requires_google_auth_gte_1_25_0
def test_analytics_admin_service_base_transport_with_credentials_file():
# Instantiate the base transport with a credentials file
with mock.patch.object(
Expand All @@ -21468,31 +21449,6 @@ def test_analytics_admin_service_base_transport_with_credentials_file():
)


@requires_google_auth_lt_1_25_0
def test_analytics_admin_service_base_transport_with_credentials_file_old_google_auth():
# Instantiate the base transport with a credentials file
with mock.patch.object(
google.auth, "load_credentials_from_file", autospec=True
) as load_creds, mock.patch(
"google.analytics.admin_v1alpha.services.analytics_admin_service.transports.AnalyticsAdminServiceTransport._prep_wrapped_messages"
) as Transport:
Transport.return_value = None
load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
transport = transports.AnalyticsAdminServiceTransport(
credentials_file="credentials.json", quota_project_id="octopus",
)
load_creds.assert_called_once_with(
"credentials.json",
scopes=(
"https://www.googleapis.com/auth/analytics.edit",
"https://www.googleapis.com/auth/analytics.manage.users",
"https://www.googleapis.com/auth/analytics.manage.users.readonly",
"https://www.googleapis.com/auth/analytics.readonly",
),
quota_project_id="octopus",
)


def test_analytics_admin_service_base_transport_with_adc():
# Test the default credentials are used if credentials and credentials_file are None.
with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch(
Expand All @@ -21504,7 +21460,6 @@ def test_analytics_admin_service_base_transport_with_adc():
adc.assert_called_once()


@requires_google_auth_gte_1_25_0
def test_analytics_admin_service_auth_adc():
# If no credentials are provided, we should use ADC credentials.
with mock.patch.object(google.auth, "default", autospec=True) as adc:
Expand All @@ -21522,31 +21477,13 @@ def test_analytics_admin_service_auth_adc():
)


@requires_google_auth_lt_1_25_0
def test_analytics_admin_service_auth_adc_old_google_auth():
# If no credentials are provided, we should use ADC credentials.
with mock.patch.object(google.auth, "default", autospec=True) as adc:
adc.return_value = (ga_credentials.AnonymousCredentials(), None)
AnalyticsAdminServiceClient()
adc.assert_called_once_with(
scopes=(
"https://www.googleapis.com/auth/analytics.edit",
"https://www.googleapis.com/auth/analytics.manage.users",
"https://www.googleapis.com/auth/analytics.manage.users.readonly",
"https://www.googleapis.com/auth/analytics.readonly",
),
quota_project_id=None,
)


@pytest.mark.parametrize(
"transport_class",
[
transports.AnalyticsAdminServiceGrpcTransport,
transports.AnalyticsAdminServiceGrpcAsyncIOTransport,
],
)
@requires_google_auth_gte_1_25_0
def test_analytics_admin_service_transport_auth_adc(transport_class):
# If credentials and host are not provided, the transport class should use
# ADC credentials.
Expand All @@ -21565,31 +21502,6 @@ def test_analytics_admin_service_transport_auth_adc(transport_class):
)


@pytest.mark.parametrize(
"transport_class",
[
transports.AnalyticsAdminServiceGrpcTransport,
transports.AnalyticsAdminServiceGrpcAsyncIOTransport,
],
)
@requires_google_auth_lt_1_25_0
def test_analytics_admin_service_transport_auth_adc_old_google_auth(transport_class):
# If credentials and host are not provided, the transport class should use
# ADC credentials.
with mock.patch.object(google.auth, "default", autospec=True) as adc:
adc.return_value = (ga_credentials.AnonymousCredentials(), None)
transport_class(quota_project_id="octopus")
adc.assert_called_once_with(
scopes=(
"https://www.googleapis.com/auth/analytics.edit",
"https://www.googleapis.com/auth/analytics.manage.users",
"https://www.googleapis.com/auth/analytics.manage.users.readonly",
"https://www.googleapis.com/auth/analytics.readonly",
),
quota_project_id="octopus",
)


@pytest.mark.parametrize(
"transport_class,grpc_helpers",
[
Expand Down

0 comments on commit be96ebc

Please sign in to comment.