diff --git a/google/analytics/data/__init__.py b/google/analytics/data/__init__.py index f6e294d..dbfffbd 100644 --- a/google/analytics/data/__init__.py +++ b/google/analytics/data/__init__.py @@ -31,6 +31,12 @@ from google.analytics.data_v1beta.types.analytics_data_api import ( BatchRunReportsResponse, ) +from google.analytics.data_v1beta.types.analytics_data_api import ( + CheckCompatibilityRequest, +) +from google.analytics.data_v1beta.types.analytics_data_api import ( + CheckCompatibilityResponse, +) from google.analytics.data_v1beta.types.analytics_data_api import GetMetadataRequest from google.analytics.data_v1beta.types.analytics_data_api import Metadata from google.analytics.data_v1beta.types.analytics_data_api import RunPivotReportRequest @@ -49,6 +55,7 @@ from google.analytics.data_v1beta.types.data import CohortsRange from google.analytics.data_v1beta.types.data import DateRange from google.analytics.data_v1beta.types.data import Dimension +from google.analytics.data_v1beta.types.data import DimensionCompatibility from google.analytics.data_v1beta.types.data import DimensionExpression from google.analytics.data_v1beta.types.data import DimensionHeader from google.analytics.data_v1beta.types.data import DimensionMetadata @@ -57,6 +64,7 @@ from google.analytics.data_v1beta.types.data import FilterExpression from google.analytics.data_v1beta.types.data import FilterExpressionList from google.analytics.data_v1beta.types.data import Metric +from google.analytics.data_v1beta.types.data import MetricCompatibility from google.analytics.data_v1beta.types.data import MetricHeader from google.analytics.data_v1beta.types.data import MetricMetadata from google.analytics.data_v1beta.types.data import MetricValue @@ -70,6 +78,7 @@ from google.analytics.data_v1beta.types.data import QuotaStatus from google.analytics.data_v1beta.types.data import ResponseMetaData from google.analytics.data_v1beta.types.data import Row +from google.analytics.data_v1beta.types.data import Compatibility from google.analytics.data_v1beta.types.data import MetricAggregation from google.analytics.data_v1beta.types.data import MetricType @@ -80,6 +89,8 @@ "BatchRunPivotReportsResponse", "BatchRunReportsRequest", "BatchRunReportsResponse", + "CheckCompatibilityRequest", + "CheckCompatibilityResponse", "GetMetadataRequest", "Metadata", "RunPivotReportRequest", @@ -94,6 +105,7 @@ "CohortsRange", "DateRange", "Dimension", + "DimensionCompatibility", "DimensionExpression", "DimensionHeader", "DimensionMetadata", @@ -102,6 +114,7 @@ "FilterExpression", "FilterExpressionList", "Metric", + "MetricCompatibility", "MetricHeader", "MetricMetadata", "MetricValue", @@ -115,6 +128,7 @@ "QuotaStatus", "ResponseMetaData", "Row", + "Compatibility", "MetricAggregation", "MetricType", ) diff --git a/google/analytics/data_v1beta/__init__.py b/google/analytics/data_v1beta/__init__.py index 0f581f7..9b9f490 100644 --- a/google/analytics/data_v1beta/__init__.py +++ b/google/analytics/data_v1beta/__init__.py @@ -21,6 +21,8 @@ from .types.analytics_data_api import BatchRunPivotReportsResponse from .types.analytics_data_api import BatchRunReportsRequest from .types.analytics_data_api import BatchRunReportsResponse +from .types.analytics_data_api import CheckCompatibilityRequest +from .types.analytics_data_api import CheckCompatibilityResponse from .types.analytics_data_api import GetMetadataRequest from .types.analytics_data_api import Metadata from .types.analytics_data_api import RunPivotReportRequest @@ -35,6 +37,7 @@ from .types.data import CohortsRange from .types.data import DateRange from .types.data import Dimension +from .types.data import DimensionCompatibility from .types.data import DimensionExpression from .types.data import DimensionHeader from .types.data import DimensionMetadata @@ -43,6 +46,7 @@ from .types.data import FilterExpression from .types.data import FilterExpressionList from .types.data import Metric +from .types.data import MetricCompatibility from .types.data import MetricHeader from .types.data import MetricMetadata from .types.data import MetricValue @@ -56,6 +60,7 @@ from .types.data import QuotaStatus from .types.data import ResponseMetaData from .types.data import Row +from .types.data import Compatibility from .types.data import MetricAggregation from .types.data import MetricType @@ -66,12 +71,16 @@ "BatchRunReportsRequest", "BatchRunReportsResponse", "BetaAnalyticsDataClient", + "CheckCompatibilityRequest", + "CheckCompatibilityResponse", "Cohort", "CohortReportSettings", "CohortSpec", "CohortsRange", + "Compatibility", "DateRange", "Dimension", + "DimensionCompatibility", "DimensionExpression", "DimensionHeader", "DimensionMetadata", @@ -83,6 +92,7 @@ "Metadata", "Metric", "MetricAggregation", + "MetricCompatibility", "MetricHeader", "MetricMetadata", "MetricType", diff --git a/google/analytics/data_v1beta/gapic_metadata.json b/google/analytics/data_v1beta/gapic_metadata.json index b515c4d..b0490ce 100644 --- a/google/analytics/data_v1beta/gapic_metadata.json +++ b/google/analytics/data_v1beta/gapic_metadata.json @@ -20,6 +20,11 @@ "batch_run_reports" ] }, + "CheckCompatibility": { + "methods": [ + "check_compatibility" + ] + }, "GetMetadata": { "methods": [ "get_metadata" @@ -55,6 +60,11 @@ "batch_run_reports" ] }, + "CheckCompatibility": { + "methods": [ + "check_compatibility" + ] + }, "GetMetadata": { "methods": [ "get_metadata" 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 c8be304..c07fd7a 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 @@ -514,6 +514,70 @@ async def run_realtime_report( # Done; return the response. return response + async def check_compatibility( + self, + request: analytics_data_api.CheckCompatibilityRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.CheckCompatibilityResponse: + r"""This compatibility method lists dimensions and + metrics that can be added to a report request and + maintain compatibility. This method fails if the + request's dimensions and metrics are incompatible. + In Google Analytics, reports fail if they request + incompatible dimensions and/or metrics; in that case, + you will need to remove dimensions and/or metrics from + the incompatible report until the report is compatible. + The Realtime and Core reports have different + compatibility rules. This method checks compatibility + for Core reports. + + Args: + request (:class:`google.analytics.data_v1beta.types.CheckCompatibilityRequest`): + The request object. The request for compatibility + information for a report's dimensions and metrics. Check + compatibility provides a preview of the compatibility of + a report; fields shared with the `runReport` request + should be the same values as in your `runReport` + request. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1beta.types.CheckCompatibilityResponse: + The compatibility response with the + compatibility of each dimension & + metric. + + """ + # Create or coerce a protobuf request object. + request = analytics_data_api.CheckCompatibilityRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.check_compatibility, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("property", request.property),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 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 330cde9..e5818a0 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/client.py @@ -705,6 +705,71 @@ def run_realtime_report( # Done; return the response. return response + def check_compatibility( + self, + request: analytics_data_api.CheckCompatibilityRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> analytics_data_api.CheckCompatibilityResponse: + r"""This compatibility method lists dimensions and + metrics that can be added to a report request and + maintain compatibility. This method fails if the + request's dimensions and metrics are incompatible. + In Google Analytics, reports fail if they request + incompatible dimensions and/or metrics; in that case, + you will need to remove dimensions and/or metrics from + the incompatible report until the report is compatible. + The Realtime and Core reports have different + compatibility rules. This method checks compatibility + for Core reports. + + Args: + request (google.analytics.data_v1beta.types.CheckCompatibilityRequest): + The request object. The request for compatibility + information for a report's dimensions and metrics. Check + compatibility provides a preview of the compatibility of + a report; fields shared with the `runReport` request + should be the same values as in your `runReport` + request. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.analytics.data_v1beta.types.CheckCompatibilityResponse: + The compatibility response with the + compatibility of each dimension & + metric. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a analytics_data_api.CheckCompatibilityRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, analytics_data_api.CheckCompatibilityRequest): + request = analytics_data_api.CheckCompatibilityRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.check_compatibility] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("property", request.property),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 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 0b359f0..30f8902 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 @@ -175,6 +175,9 @@ def _prep_wrapped_messages(self, client_info): self.run_realtime_report: gapic_v1.method.wrap_method( self.run_realtime_report, default_timeout=60.0, client_info=client_info, ), + self.check_compatibility: gapic_v1.method.wrap_method( + self.check_compatibility, default_timeout=None, client_info=client_info, + ), } @property @@ -246,5 +249,17 @@ def run_realtime_report( ]: raise NotImplementedError() + @property + def check_compatibility( + self, + ) -> Callable[ + [analytics_data_api.CheckCompatibilityRequest], + Union[ + analytics_data_api.CheckCompatibilityResponse, + Awaitable[analytics_data_api.CheckCompatibilityResponse], + ], + ]: + 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 b283aff..3592f8d 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 @@ -423,5 +423,44 @@ def run_realtime_report( ) return self._stubs["run_realtime_report"] + @property + def check_compatibility( + self, + ) -> Callable[ + [analytics_data_api.CheckCompatibilityRequest], + analytics_data_api.CheckCompatibilityResponse, + ]: + r"""Return a callable for the check compatibility method over gRPC. + + This compatibility method lists dimensions and + metrics that can be added to a report request and + maintain compatibility. This method fails if the + request's dimensions and metrics are incompatible. + In Google Analytics, reports fail if they request + incompatible dimensions and/or metrics; in that case, + you will need to remove dimensions and/or metrics from + the incompatible report until the report is compatible. + The Realtime and Core reports have different + compatibility rules. This method checks compatibility + for Core reports. + + Returns: + Callable[[~.CheckCompatibilityRequest], + ~.CheckCompatibilityResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "check_compatibility" not in self._stubs: + self._stubs["check_compatibility"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1beta.BetaAnalyticsData/CheckCompatibility", + request_serializer=analytics_data_api.CheckCompatibilityRequest.serialize, + response_deserializer=analytics_data_api.CheckCompatibilityResponse.deserialize, + ) + return self._stubs["check_compatibility"] + __all__ = ("BetaAnalyticsDataGrpcTransport",) diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py index 8ab0eab..0b0e661 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py @@ -429,5 +429,44 @@ def run_realtime_report( ) return self._stubs["run_realtime_report"] + @property + def check_compatibility( + self, + ) -> Callable[ + [analytics_data_api.CheckCompatibilityRequest], + Awaitable[analytics_data_api.CheckCompatibilityResponse], + ]: + r"""Return a callable for the check compatibility method over gRPC. + + This compatibility method lists dimensions and + metrics that can be added to a report request and + maintain compatibility. This method fails if the + request's dimensions and metrics are incompatible. + In Google Analytics, reports fail if they request + incompatible dimensions and/or metrics; in that case, + you will need to remove dimensions and/or metrics from + the incompatible report until the report is compatible. + The Realtime and Core reports have different + compatibility rules. This method checks compatibility + for Core reports. + + Returns: + Callable[[~.CheckCompatibilityRequest], + Awaitable[~.CheckCompatibilityResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "check_compatibility" not in self._stubs: + self._stubs["check_compatibility"] = self.grpc_channel.unary_unary( + "/google.analytics.data.v1beta.BetaAnalyticsData/CheckCompatibility", + request_serializer=analytics_data_api.CheckCompatibilityRequest.serialize, + response_deserializer=analytics_data_api.CheckCompatibilityResponse.deserialize, + ) + return self._stubs["check_compatibility"] + __all__ = ("BetaAnalyticsDataGrpcAsyncIOTransport",) diff --git a/google/analytics/data_v1beta/types/__init__.py b/google/analytics/data_v1beta/types/__init__.py index 80f4321..408fe4f 100644 --- a/google/analytics/data_v1beta/types/__init__.py +++ b/google/analytics/data_v1beta/types/__init__.py @@ -18,6 +18,8 @@ BatchRunPivotReportsResponse, BatchRunReportsRequest, BatchRunReportsResponse, + CheckCompatibilityRequest, + CheckCompatibilityResponse, GetMetadataRequest, Metadata, RunPivotReportRequest, @@ -34,6 +36,7 @@ CohortsRange, DateRange, Dimension, + DimensionCompatibility, DimensionExpression, DimensionHeader, DimensionMetadata, @@ -42,6 +45,7 @@ FilterExpression, FilterExpressionList, Metric, + MetricCompatibility, MetricHeader, MetricMetadata, MetricValue, @@ -55,6 +59,7 @@ QuotaStatus, ResponseMetaData, Row, + Compatibility, MetricAggregation, MetricType, ) @@ -64,6 +69,8 @@ "BatchRunPivotReportsResponse", "BatchRunReportsRequest", "BatchRunReportsResponse", + "CheckCompatibilityRequest", + "CheckCompatibilityResponse", "GetMetadataRequest", "Metadata", "RunPivotReportRequest", @@ -78,6 +85,7 @@ "CohortsRange", "DateRange", "Dimension", + "DimensionCompatibility", "DimensionExpression", "DimensionHeader", "DimensionMetadata", @@ -86,6 +94,7 @@ "FilterExpression", "FilterExpressionList", "Metric", + "MetricCompatibility", "MetricHeader", "MetricMetadata", "MetricValue", @@ -99,6 +108,7 @@ "QuotaStatus", "ResponseMetaData", "Row", + "Compatibility", "MetricAggregation", "MetricType", ) diff --git a/google/analytics/data_v1beta/types/analytics_data_api.py b/google/analytics/data_v1beta/types/analytics_data_api.py index 8a188ac..08357c3 100644 --- a/google/analytics/data_v1beta/types/analytics_data_api.py +++ b/google/analytics/data_v1beta/types/analytics_data_api.py @@ -21,6 +21,8 @@ __protobuf__ = proto.module( package="google.analytics.data.v1beta", manifest={ + "CheckCompatibilityRequest", + "CheckCompatibilityResponse", "Metadata", "RunReportRequest", "RunReportResponse", @@ -37,6 +39,74 @@ ) +class CheckCompatibilityRequest(proto.Message): + r"""The request for compatibility information for a report's dimensions + and metrics. Check compatibility provides a preview of the + compatibility of a report; fields shared with the ``runReport`` + request should be the same values as in your ``runReport`` request. + + Attributes: + property (str): + A Google Analytics GA4 property identifier whose events are + tracked. To learn more, see `where to find your Property + ID `__. + ``property`` should be the same value as in your + ``runReport`` request. + + Example: properties/1234 + + Set the Property ID to 0 for compatibility checking on + dimensions and metrics common to all properties. In this + special mode, this method will not return custom dimensions + and metrics. + dimensions (Sequence[google.analytics.data_v1beta.types.Dimension]): + The dimensions in this report. ``dimensions`` should be the + same value as in your ``runReport`` request. + metrics (Sequence[google.analytics.data_v1beta.types.Metric]): + The metrics in this report. ``metrics`` should be the same + value as in your ``runReport`` request. + dimension_filter (google.analytics.data_v1beta.types.FilterExpression): + The filter clause of dimensions. ``dimensionFilter`` should + be the same value as in your ``runReport`` request. + metric_filter (google.analytics.data_v1beta.types.FilterExpression): + The filter clause of metrics. ``metricFilter`` should be the + same value as in your ``runReport`` request + compatibility_filter (google.analytics.data_v1beta.types.Compatibility): + Filters the dimensions and metrics in the response to just + this compatibility. Commonly used as + ``”compatibilityFilter”: “COMPATIBLE”`` to only return + compatible dimensions & metrics. + """ + + property = proto.Field(proto.STRING, number=1,) + dimensions = proto.RepeatedField(proto.MESSAGE, number=2, message=data.Dimension,) + metrics = proto.RepeatedField(proto.MESSAGE, number=3, message=data.Metric,) + dimension_filter = proto.Field( + proto.MESSAGE, number=4, message=data.FilterExpression, + ) + metric_filter = proto.Field(proto.MESSAGE, number=5, message=data.FilterExpression,) + compatibility_filter = proto.Field(proto.ENUM, number=6, enum=data.Compatibility,) + + +class CheckCompatibilityResponse(proto.Message): + r"""The compatibility response with the compatibility of each + dimension & metric. + + Attributes: + dimension_compatibilities (Sequence[google.analytics.data_v1beta.types.DimensionCompatibility]): + The compatibility of each dimension. + metric_compatibilities (Sequence[google.analytics.data_v1beta.types.MetricCompatibility]): + The compatibility of each metric. + """ + + dimension_compatibilities = proto.RepeatedField( + proto.MESSAGE, number=1, message=data.DimensionCompatibility, + ) + metric_compatibilities = proto.RepeatedField( + proto.MESSAGE, number=2, message=data.MetricCompatibility, + ) + + class Metadata(proto.Message): r"""The dimensions and metrics currently accepted in reporting methods. @@ -81,15 +151,15 @@ class RunReportRequest(proto.Message): both date ranges. In a cohort request, this ``dateRanges`` must be unspecified. dimension_filter (google.analytics.data_v1beta.types.FilterExpression): - The filter clause of dimensions. Dimensions - must be requested to be used in this filter. - Metrics cannot be used in this filter. + Dimension filters allow you to ask for only specific + dimension values in the report. To learn more, see + `Fundamentals of Dimension + Filters `__ + for examples. Metrics cannot be used in this filter. metric_filter (google.analytics.data_v1beta.types.FilterExpression): The filter clause of metrics. Applied at post aggregation phase, similar to SQL having-clause. - Metrics must be requested to be used in this - filter. Dimensions cannot be used in this - filter. + Dimensions cannot be used in this filter. offset (int): The row count of the start row. The first row is counted as row 0. diff --git a/google/analytics/data_v1beta/types/data.py b/google/analytics/data_v1beta/types/data.py index 58c19aa..97d3d99 100644 --- a/google/analytics/data_v1beta/types/data.py +++ b/google/analytics/data_v1beta/types/data.py @@ -21,6 +21,7 @@ manifest={ "MetricAggregation", "MetricType", + "Compatibility", "DateRange", "MinuteRange", "Dimension", @@ -48,6 +49,8 @@ "QuotaStatus", "DimensionMetadata", "MetricMetadata", + "DimensionCompatibility", + "MetricCompatibility", }, ) @@ -78,6 +81,13 @@ class MetricType(proto.Enum): TYPE_KILOMETERS = 13 +class Compatibility(proto.Enum): + r"""The compatibility types for a single dimension or metric.""" + COMPATIBILITY_UNSPECIFIED = 0 + COMPATIBLE = 1 + INCOMPATIBLE = 2 + + class DateRange(proto.Message): r"""A contiguous set of days: startDate, startDate + 1, ..., endDate. Requests are allowed up to 4 date ranges. @@ -993,6 +1003,10 @@ class DimensionMetadata(proto.Message): custom_definition (bool): True if the dimension is a custom dimension for this property. + category (str): + The display name of the category that this + dimension belongs to. Similar dimensions and + metrics are categorized together. """ api_name = proto.Field(proto.STRING, number=1,) @@ -1000,6 +1014,7 @@ class DimensionMetadata(proto.Message): description = proto.Field(proto.STRING, number=3,) deprecated_api_names = proto.RepeatedField(proto.STRING, number=4,) custom_definition = proto.Field(proto.BOOL, number=5,) + category = proto.Field(proto.STRING, number=7,) class MetricMetadata(proto.Message): @@ -1030,6 +1045,10 @@ class MetricMetadata(proto.Message): custom_definition (bool): True if the metric is a custom metric for this property. + category (str): + The display name of the category that this + metrics belongs to. Similar dimensions and + metrics are categorized together. """ api_name = proto.Field(proto.STRING, number=1,) @@ -1039,6 +1058,51 @@ class MetricMetadata(proto.Message): type_ = proto.Field(proto.ENUM, number=5, enum="MetricType",) expression = proto.Field(proto.STRING, number=6,) custom_definition = proto.Field(proto.BOOL, number=7,) + category = proto.Field(proto.STRING, number=10,) + + +class DimensionCompatibility(proto.Message): + r"""The compatibility for a single dimension. + Attributes: + dimension_metadata (google.analytics.data_v1beta.types.DimensionMetadata): + The dimension metadata contains the API name + for this compatibility information. The + dimension metadata also contains other helpful + information like the UI name and description. + compatibility (google.analytics.data_v1beta.types.Compatibility): + The compatibility of this dimension. If the + compatibility is COMPATIBLE, this dimension can + be successfully added to the report. + """ + + dimension_metadata = proto.Field( + proto.MESSAGE, number=1, optional=True, message="DimensionMetadata", + ) + compatibility = proto.Field( + proto.ENUM, number=2, optional=True, enum="Compatibility", + ) + + +class MetricCompatibility(proto.Message): + r"""The compatibility for a single metric. + Attributes: + metric_metadata (google.analytics.data_v1beta.types.MetricMetadata): + The metric metadata contains the API name for + this compatibility information. The metric + metadata also contains other helpful information + like the UI name and description. + compatibility (google.analytics.data_v1beta.types.Compatibility): + The compatibility of this metric. If the + compatibility is COMPATIBLE, this metric can be + successfully added to the report. + """ + + metric_metadata = proto.Field( + proto.MESSAGE, number=1, optional=True, message="MetricMetadata", + ) + compatibility = proto.Field( + proto.ENUM, number=2, optional=True, enum="Compatibility", + ) __all__ = tuple(sorted(__protobuf__.manifest)) 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 e73a163..7a61a54 100644 --- a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -1431,6 +1431,149 @@ async def test_run_realtime_report_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] +def test_check_compatibility( + transport: str = "grpc", request_type=analytics_data_api.CheckCompatibilityRequest +): + client = BetaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_compatibility), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = analytics_data_api.CheckCompatibilityResponse() + response = client.check_compatibility(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.CheckCompatibilityRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.CheckCompatibilityResponse) + + +def test_check_compatibility_from_dict(): + test_check_compatibility(request_type=dict) + + +def test_check_compatibility_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = BetaAnalyticsDataClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_compatibility), "__call__" + ) as call: + client.check_compatibility() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.CheckCompatibilityRequest() + + +@pytest.mark.asyncio +async def test_check_compatibility_async( + transport: str = "grpc_asyncio", + request_type=analytics_data_api.CheckCompatibilityRequest, +): + client = BetaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_compatibility), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.CheckCompatibilityResponse() + ) + response = await client.check_compatibility(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == analytics_data_api.CheckCompatibilityRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, analytics_data_api.CheckCompatibilityResponse) + + +@pytest.mark.asyncio +async def test_check_compatibility_async_from_dict(): + await test_check_compatibility_async(request_type=dict) + + +def test_check_compatibility_field_headers(): + client = BetaAnalyticsDataClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.CheckCompatibilityRequest() + + request.property = "property/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_compatibility), "__call__" + ) as call: + call.return_value = analytics_data_api.CheckCompatibilityResponse() + client.check_compatibility(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_check_compatibility_field_headers_async(): + client = BetaAnalyticsDataAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = analytics_data_api.CheckCompatibilityRequest() + + request.property = "property/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_compatibility), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + analytics_data_api.CheckCompatibilityResponse() + ) + await client.check_compatibility(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BetaAnalyticsDataGrpcTransport( @@ -1534,6 +1677,7 @@ def test_beta_analytics_data_base_transport(): "batch_run_pivot_reports", "get_metadata", "run_realtime_report", + "check_compatibility", ) for method in methods: with pytest.raises(NotImplementedError):