Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -250,5 +251,9 @@ def check_compatibility(
]:
raise NotImplementedError()

@property
def kind(self) -> str:
raise NotImplementedError()


__all__ = ("BetaAnalyticsDataTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,9 @@ def check_compatibility(
def close(self):
self.grpc_channel.close()

@property
def kind(self) -> str:
return "grpc"


__all__ = ("BetaAnalyticsDataGrpcTransport",)
79 changes: 62 additions & 17 deletions tests/unit/gapic/data_v1beta/test_beta_analytics_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down