diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py b/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py index 9090976..e68e9c3 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/async_client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -220,7 +220,6 @@ async def run_report( Dimensions break down metrics across some common criteria, such as country or event name. - .. code-block:: python from google.analytics import data_v1beta @@ -297,7 +296,6 @@ async def run_pivot_report( in a pivot. Multiple pivots can be specified to further dissect your data. - .. code-block:: python from google.analytics import data_v1beta @@ -371,7 +369,6 @@ async def batch_run_reports( r"""Returns multiple reports in a batch. All reports must be for the same GA4 Property. - .. code-block:: python from google.analytics import data_v1beta @@ -445,7 +442,6 @@ async def batch_run_pivot_reports( r"""Returns multiple pivot reports in a batch. All reports must be for the same GA4 Property. - .. code-block:: python from google.analytics import data_v1beta @@ -529,7 +525,6 @@ async def get_metadata( metadata are dimensions and metrics applicable to any property such as ``country`` and ``totalUsers``. - .. code-block:: python from google.analytics import data_v1beta @@ -637,7 +632,6 @@ async def run_realtime_report( property. These reports show events and usage from the last 30 minutes. - .. code-block:: python from google.analytics import data_v1beta @@ -720,7 +714,6 @@ async def check_compatibility( compatibility rules. This method checks compatibility for Core reports. - .. code-block:: python from google.analytics import data_v1beta diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/client.py b/google/analytics/data_v1beta/services/beta_analytics_data/client.py index f990474..310c240 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib @@ -437,7 +437,6 @@ def run_report( Dimensions break down metrics across some common criteria, such as country or event name. - .. code-block:: python from google.analytics import data_v1beta @@ -515,7 +514,6 @@ def run_pivot_report( in a pivot. Multiple pivots can be specified to further dissect your data. - .. code-block:: python from google.analytics import data_v1beta @@ -590,7 +588,6 @@ def batch_run_reports( r"""Returns multiple reports in a batch. All reports must be for the same GA4 Property. - .. code-block:: python from google.analytics import data_v1beta @@ -665,7 +662,6 @@ def batch_run_pivot_reports( r"""Returns multiple pivot reports in a batch. All reports must be for the same GA4 Property. - .. code-block:: python from google.analytics import data_v1beta @@ -750,7 +746,6 @@ def get_metadata( metadata are dimensions and metrics applicable to any property such as ``country`` and ``totalUsers``. - .. code-block:: python from google.analytics import data_v1beta @@ -858,7 +853,6 @@ def run_realtime_report( property. These reports show events and usage from the last 30 minutes. - .. code-block:: python from google.analytics import data_v1beta @@ -942,7 +936,6 @@ def check_compatibility( compatibility rules. This method checks compatibility for Core reports. - .. code-block:: python from google.analytics import data_v1beta diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py index e4a1ce5..677ec98 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py @@ -83,6 +83,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -250,5 +251,9 @@ def check_compatibility( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("BetaAnalyticsDataTransport",) diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py index 946c492..acec4e0 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py @@ -467,5 +467,9 @@ def check_compatibility( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("BetaAnalyticsDataGrpcTransport",) diff --git a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py index ab39531..92a1887 100644 --- a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -90,24 +90,26 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - BetaAnalyticsDataClient, - BetaAnalyticsDataAsyncClient, + (BetaAnalyticsDataClient, "grpc"), + (BetaAnalyticsDataAsyncClient, "grpc_asyncio"), ], ) -def test_beta_analytics_data_client_from_service_account_info(client_class): +def test_beta_analytics_data_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "analyticsdata.googleapis.com:443" + assert client.transport._host == ("analyticsdata.googleapis.com:443") @pytest.mark.parametrize( @@ -136,27 +138,33 @@ def test_beta_analytics_data_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - BetaAnalyticsDataClient, - BetaAnalyticsDataAsyncClient, + (BetaAnalyticsDataClient, "grpc"), + (BetaAnalyticsDataAsyncClient, "grpc_asyncio"), ], ) -def test_beta_analytics_data_client_from_service_account_file(client_class): +def test_beta_analytics_data_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "analyticsdata.googleapis.com:443" + assert client.transport._host == ("analyticsdata.googleapis.com:443") def test_beta_analytics_data_client_get_transport_class(): @@ -1929,6 +1937,19 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = BetaAnalyticsDataClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BetaAnalyticsDataClient( @@ -1977,6 +1998,14 @@ def test_beta_analytics_data_base_transport(): with pytest.raises(NotImplementedError): transport.close() + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_beta_analytics_data_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -2136,24 +2165,40 @@ def test_beta_analytics_data_grpc_transport_client_cert_source_for_mtls( ) -def test_beta_analytics_data_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_beta_analytics_data_host_no_port(transport_name): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="analyticsdata.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "analyticsdata.googleapis.com:443" + assert client.transport._host == ("analyticsdata.googleapis.com:443") -def test_beta_analytics_data_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_beta_analytics_data_host_with_port(transport_name): client = BetaAnalyticsDataClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="analyticsdata.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "analyticsdata.googleapis.com:8000" + assert client.transport._host == ("analyticsdata.googleapis.com:8000") def test_beta_analytics_data_grpc_transport_channel():