From 4570fb19b241a718f62d0cab5a53e028576e88bc Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 1 Mar 2021 17:34:26 +0100 Subject: [PATCH 1/6] chore(deps): update dependency google-analytics-data to v0.4.0 (#41) --- samples/snippets/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 44013c1..fcb2cda 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-analytics-data==0.3.0 +google-analytics-data==0.4.0 From 58f834e80510abdcbb49801e2901e1ee44653396 Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Thu, 4 Mar 2021 14:04:19 -0700 Subject: [PATCH 2/6] chore: require samples checks (#17) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> --- .github/sync-repo-settings.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/sync-repo-settings.yaml diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml new file mode 100644 index 0000000..af59935 --- /dev/null +++ b/.github/sync-repo-settings.yaml @@ -0,0 +1,13 @@ +# https://github.com/googleapis/repo-automation-bots/tree/master/packages/sync-repo-settings +# Rules for master branch protection +branchProtectionRules: +# Identifies the protection rule pattern. Name of the branch to be protected. +# Defaults to `master` +- pattern: master + requiredStatusCheckContexts: + - 'Kokoro' + - 'cla/google' + - 'Samples - Lint' + - 'Samples - Python 3.6' + - 'Samples - Python 3.7' + - 'Samples - Python 3.8' From fdebf9b96e915a06fecaeb83c1ca59de077249a8 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 10 Mar 2021 16:22:26 -0800 Subject: [PATCH 3/6] fix: fix from_service_account_info for async clients (#44) * test: install pyopenssl for mtls testing Source-Author: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Source-Date: Tue Mar 2 12:27:56 2021 -0800 Source-Repo: googleapis/synthtool Source-Sha: 0780323da96d5a53925fe0547757181fe76e8f1e Source-Link: https://github.com/googleapis/synthtool/commit/0780323da96d5a53925fe0547757181fe76e8f1e --- .../alpha_analytics_data/async_client.py | 32 ++++- .../beta_analytics_data/async_client.py | 32 ++++- noxfile.py | 3 + synth.metadata | 124 +++++++++++++++++- tests/unit/gapic/data_v1alpha/__init__.py | 15 +++ .../data_v1alpha/test_alpha_analytics_data.py | 112 +++++++++++++++- tests/unit/gapic/data_v1beta/__init__.py | 15 +++ .../data_v1beta/test_beta_analytics_data.py | 112 +++++++++++++++- 8 files changed, 433 insertions(+), 12 deletions(-) diff --git a/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py b/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py index cf5ba1b..7d5a1fe 100644 --- a/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py +++ b/google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py @@ -76,8 +76,36 @@ class AlphaAnalyticsDataAsyncClient: AlphaAnalyticsDataClient.parse_common_location_path ) - from_service_account_info = AlphaAnalyticsDataClient.from_service_account_info - from_service_account_file = AlphaAnalyticsDataClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + AlphaAnalyticsDataAsyncClient: The constructed client. + """ + return AlphaAnalyticsDataClient.from_service_account_info.__func__(AlphaAnalyticsDataAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + AlphaAnalyticsDataAsyncClient: The constructed client. + """ + return AlphaAnalyticsDataClient.from_service_account_file.__func__(AlphaAnalyticsDataAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property 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 e4dd62c..523b0f4 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 @@ -77,8 +77,36 @@ class BetaAnalyticsDataAsyncClient: BetaAnalyticsDataClient.parse_common_location_path ) - from_service_account_info = BetaAnalyticsDataClient.from_service_account_info - from_service_account_file = BetaAnalyticsDataClient.from_service_account_file + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + BetaAnalyticsDataAsyncClient: The constructed client. + """ + return BetaAnalyticsDataClient.from_service_account_info.__func__(BetaAnalyticsDataAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + BetaAnalyticsDataAsyncClient: The constructed client. + """ + return BetaAnalyticsDataClient.from_service_account_file.__func__(BetaAnalyticsDataAsyncClient, filename, *args, **kwargs) # type: ignore + from_service_account_json = from_service_account_file @property diff --git a/noxfile.py b/noxfile.py index 1ee6cab..08d9470 100644 --- a/noxfile.py +++ b/noxfile.py @@ -123,6 +123,9 @@ def system(session): # Sanity check: Only run tests if the environment variable is set. if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): session.skip("Credentials must be set via environment variable") + # Install pyopenssl for mTLS testing. + if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": + session.install("pyopenssl") system_test_exists = os.path.exists(system_test_path) system_test_folder_exists = os.path.exists(system_test_folder_path) diff --git a/synth.metadata b/synth.metadata index fdccd7c..2e3e66a 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,22 +3,30 @@ { "git": { "name": ".", - "remote": "git@github.com:googleapis/python-analytics-data", - "sha": "3b9a193edfba38c9e8f72580f400514fa283a79c" + "remote": "https://github.com/googleapis/python-analytics-data.git", + "sha": "58f834e80510abdcbb49801e2901e1ee44653396" + } + }, + { + "git": { + "name": "googleapis", + "remote": "https://github.com/googleapis/googleapis.git", + "sha": "8f117308d5bb55816953a0d6ad1a7d27a69a7d3f", + "internalRef": "361084441" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0199c79b8324fba66476300824aa931788c47e2d" + "sha": "0780323da96d5a53925fe0547757181fe76e8f1e" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0199c79b8324fba66476300824aa931788c47e2d" + "sha": "0780323da96d5a53925fe0547757181fe76e8f1e" } } ], @@ -41,5 +49,113 @@ "generator": "bazel" } } + ], + "generatedFiles": [ + ".coveragerc", + ".flake8", + ".github/CONTRIBUTING.md", + ".github/ISSUE_TEMPLATE/bug_report.md", + ".github/ISSUE_TEMPLATE/feature_request.md", + ".github/ISSUE_TEMPLATE/support_request.md", + ".github/PULL_REQUEST_TEMPLATE.md", + ".github/header-checker-lint.yml", + ".github/release-please.yml", + ".github/snippet-bot.yml", + ".gitignore", + ".kokoro/build.sh", + ".kokoro/continuous/common.cfg", + ".kokoro/continuous/continuous.cfg", + ".kokoro/docker/docs/Dockerfile", + ".kokoro/docker/docs/fetch_gpg_keys.sh", + ".kokoro/docs/common.cfg", + ".kokoro/docs/docs-presubmit.cfg", + ".kokoro/docs/docs.cfg", + ".kokoro/populate-secrets.sh", + ".kokoro/presubmit/common.cfg", + ".kokoro/presubmit/presubmit.cfg", + ".kokoro/publish-docs.sh", + ".kokoro/release.sh", + ".kokoro/release/common.cfg", + ".kokoro/release/release.cfg", + ".kokoro/samples/lint/common.cfg", + ".kokoro/samples/lint/continuous.cfg", + ".kokoro/samples/lint/periodic.cfg", + ".kokoro/samples/lint/presubmit.cfg", + ".kokoro/samples/python3.6/common.cfg", + ".kokoro/samples/python3.6/continuous.cfg", + ".kokoro/samples/python3.6/periodic.cfg", + ".kokoro/samples/python3.6/presubmit.cfg", + ".kokoro/samples/python3.7/common.cfg", + ".kokoro/samples/python3.7/continuous.cfg", + ".kokoro/samples/python3.7/periodic.cfg", + ".kokoro/samples/python3.7/presubmit.cfg", + ".kokoro/samples/python3.8/common.cfg", + ".kokoro/samples/python3.8/continuous.cfg", + ".kokoro/samples/python3.8/periodic.cfg", + ".kokoro/samples/python3.8/presubmit.cfg", + ".kokoro/test-samples.sh", + ".kokoro/trampoline.sh", + ".kokoro/trampoline_v2.sh", + ".pre-commit-config.yaml", + ".trampolinerc", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.rst", + "LICENSE", + "MANIFEST.in", + "docs/_static/custom.css", + "docs/_templates/layout.html", + "docs/conf.py", + "docs/data_v1alpha/alpha_analytics_data.rst", + "docs/data_v1alpha/services.rst", + "docs/data_v1alpha/types.rst", + "docs/data_v1beta/beta_analytics_data.rst", + "docs/data_v1beta/services.rst", + "docs/data_v1beta/types.rst", + "docs/multiprocessing.rst", + "google/analytics/data/__init__.py", + "google/analytics/data/py.typed", + "google/analytics/data_v1alpha/__init__.py", + "google/analytics/data_v1alpha/py.typed", + "google/analytics/data_v1alpha/services/__init__.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/__init__.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/async_client.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/client.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/__init__.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/base.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc.py", + "google/analytics/data_v1alpha/services/alpha_analytics_data/transports/grpc_asyncio.py", + "google/analytics/data_v1alpha/types/__init__.py", + "google/analytics/data_v1alpha/types/analytics_data_api.py", + "google/analytics/data_v1alpha/types/data.py", + "google/analytics/data_v1beta/__init__.py", + "google/analytics/data_v1beta/py.typed", + "google/analytics/data_v1beta/services/__init__.py", + "google/analytics/data_v1beta/services/beta_analytics_data/__init__.py", + "google/analytics/data_v1beta/services/beta_analytics_data/async_client.py", + "google/analytics/data_v1beta/services/beta_analytics_data/client.py", + "google/analytics/data_v1beta/services/beta_analytics_data/pagers.py", + "google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py", + "google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py", + "google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py", + "google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc_asyncio.py", + "google/analytics/data_v1beta/types/__init__.py", + "google/analytics/data_v1beta/types/analytics_data_api.py", + "google/analytics/data_v1beta/types/data.py", + "mypy.ini", + "noxfile.py", + "renovate.json", + "scripts/decrypt-secrets.sh", + "scripts/readme-gen/readme_gen.py", + "scripts/readme-gen/templates/README.tmpl.rst", + "scripts/readme-gen/templates/auth.tmpl.rst", + "scripts/readme-gen/templates/auth_api_key.tmpl.rst", + "scripts/readme-gen/templates/install_deps.tmpl.rst", + "scripts/readme-gen/templates/install_portaudio.tmpl.rst", + "setup.cfg", + "testing/.gitignore", + "tests/unit/gapic/data_v1alpha/__init__.py", + "tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py", + "tests/unit/gapic/data_v1beta/__init__.py", + "tests/unit/gapic/data_v1beta/test_beta_analytics_data.py" ] } \ No newline at end of file diff --git a/tests/unit/gapic/data_v1alpha/__init__.py b/tests/unit/gapic/data_v1alpha/__init__.py index 8b13789..42ffdf2 100644 --- a/tests/unit/gapic/data_v1alpha/__init__.py +++ b/tests/unit/gapic/data_v1alpha/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py b/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py index 59ff037..375f3eb 100644 --- a/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py +++ b/tests/unit/gapic/data_v1alpha/test_alpha_analytics_data.py @@ -89,15 +89,19 @@ def test__get_default_mtls_endpoint(): ) -def test_alpha_analytics_data_client_from_service_account_info(): +@pytest.mark.parametrize( + "client_class", [AlphaAnalyticsDataClient, AlphaAnalyticsDataAsyncClient,] +) +def test_alpha_analytics_data_client_from_service_account_info(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = AlphaAnalyticsDataClient.from_service_account_info(info) + client = client_class.from_service_account_info(info) assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "analyticsdata.googleapis.com:443" @@ -113,9 +117,11 @@ def test_alpha_analytics_data_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "analyticsdata.googleapis.com:443" @@ -486,6 +492,22 @@ def test_run_report_from_dict(): test_run_report(request_type=dict) +def test_run_report_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 = AlphaAnalyticsDataClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_report), "__call__") as call: + client.run_report() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.RunReportRequest() + + @pytest.mark.asyncio async def test_run_report_async( transport: str = "grpc_asyncio", request_type=analytics_data_api.RunReportRequest @@ -557,6 +579,22 @@ def test_run_pivot_report_from_dict(): test_run_pivot_report(request_type=dict) +def test_run_pivot_report_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 = AlphaAnalyticsDataClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_pivot_report), "__call__") as call: + client.run_pivot_report() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.RunPivotReportRequest() + + @pytest.mark.asyncio async def test_run_pivot_report_async( transport: str = "grpc_asyncio", @@ -629,6 +667,24 @@ def test_batch_run_reports_from_dict(): test_batch_run_reports(request_type=dict) +def test_batch_run_reports_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 = AlphaAnalyticsDataClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_run_reports), "__call__" + ) as call: + client.batch_run_reports() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.BatchRunReportsRequest() + + @pytest.mark.asyncio async def test_batch_run_reports_async( transport: str = "grpc_asyncio", @@ -703,6 +759,24 @@ def test_batch_run_pivot_reports_from_dict(): test_batch_run_pivot_reports(request_type=dict) +def test_batch_run_pivot_reports_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 = AlphaAnalyticsDataClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_run_pivot_reports), "__call__" + ) as call: + client.batch_run_pivot_reports() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.BatchRunPivotReportsRequest() + + @pytest.mark.asyncio async def test_batch_run_pivot_reports_async( transport: str = "grpc_asyncio", @@ -777,6 +851,22 @@ def test_get_metadata_from_dict(): test_get_metadata(request_type=dict) +def test_get_metadata_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 = AlphaAnalyticsDataClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_metadata), "__call__") as call: + client.get_metadata() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.GetMetadataRequest() + + @pytest.mark.asyncio async def test_get_metadata_async( transport: str = "grpc_asyncio", request_type=analytics_data_api.GetMetadataRequest @@ -976,6 +1066,24 @@ def test_run_realtime_report_from_dict(): test_run_realtime_report(request_type=dict) +def test_run_realtime_report_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 = AlphaAnalyticsDataClient( + credentials=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.run_realtime_report), "__call__" + ) as call: + client.run_realtime_report() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.RunRealtimeReportRequest() + + @pytest.mark.asyncio async def test_run_realtime_report_async( transport: str = "grpc_asyncio", diff --git a/tests/unit/gapic/data_v1beta/__init__.py b/tests/unit/gapic/data_v1beta/__init__.py index 8b13789..42ffdf2 100644 --- a/tests/unit/gapic/data_v1beta/__init__.py +++ b/tests/unit/gapic/data_v1beta/__init__.py @@ -1 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# 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 a23ee2f..e43b775 100644 --- a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -90,15 +90,19 @@ def test__get_default_mtls_endpoint(): ) -def test_beta_analytics_data_client_from_service_account_info(): +@pytest.mark.parametrize( + "client_class", [BetaAnalyticsDataClient, BetaAnalyticsDataAsyncClient,] +) +def test_beta_analytics_data_client_from_service_account_info(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = BetaAnalyticsDataClient.from_service_account_info(info) + client = client_class.from_service_account_info(info) assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "analyticsdata.googleapis.com:443" @@ -114,9 +118,11 @@ def test_beta_analytics_data_client_from_service_account_file(client_class): factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) client = client_class.from_service_account_json("dummy/file/path.json") assert client.transport._credentials == creds + assert isinstance(client, client_class) assert client.transport._host == "analyticsdata.googleapis.com:443" @@ -491,6 +497,22 @@ def test_run_report_from_dict(): test_run_report(request_type=dict) +def test_run_report_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=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_report), "__call__") as call: + client.run_report() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.RunReportRequest() + + @pytest.mark.asyncio async def test_run_report_async( transport: str = "grpc_asyncio", request_type=analytics_data_api.RunReportRequest @@ -765,6 +787,22 @@ def test_run_pivot_report_from_dict(): test_run_pivot_report(request_type=dict) +def test_run_pivot_report_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=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.run_pivot_report), "__call__") as call: + client.run_pivot_report() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.RunPivotReportRequest() + + @pytest.mark.asyncio async def test_run_pivot_report_async( transport: str = "grpc_asyncio", @@ -890,6 +928,24 @@ def test_batch_run_reports_from_dict(): test_batch_run_reports(request_type=dict) +def test_batch_run_reports_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=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_run_reports), "__call__" + ) as call: + client.batch_run_reports() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.BatchRunReportsRequest() + + @pytest.mark.asyncio async def test_batch_run_reports_async( transport: str = "grpc_asyncio", @@ -1021,6 +1077,24 @@ def test_batch_run_pivot_reports_from_dict(): test_batch_run_pivot_reports(request_type=dict) +def test_batch_run_pivot_reports_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=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_run_pivot_reports), "__call__" + ) as call: + client.batch_run_pivot_reports() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.BatchRunPivotReportsRequest() + + @pytest.mark.asyncio async def test_batch_run_pivot_reports_async( transport: str = "grpc_asyncio", @@ -1152,6 +1226,22 @@ def test_get_metadata_from_dict(): test_get_metadata(request_type=dict) +def test_get_metadata_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=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_metadata), "__call__") as call: + client.get_metadata() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.GetMetadataRequest() + + @pytest.mark.asyncio async def test_get_metadata_async( transport: str = "grpc_asyncio", request_type=analytics_data_api.GetMetadataRequest @@ -1353,6 +1443,24 @@ def test_run_realtime_report_from_dict(): test_run_realtime_report(request_type=dict) +def test_run_realtime_report_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=credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.run_realtime_report), "__call__" + ) as call: + client.run_realtime_report() + call.assert_called() + _, args, _ = call.mock_calls[0] + + assert args[0] == analytics_data_api.RunRealtimeReportRequest() + + @pytest.mark.asyncio async def test_run_realtime_report_async( transport: str = "grpc_asyncio", From 8fd57a340b7e052dc9c4d6c33882add75405eb8b Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Fri, 12 Mar 2021 09:15:26 -0800 Subject: [PATCH 4/6] chore: get changes from googleapis fix(v1beta): (BREAKING) rename the 'page_size', 'page_token', 'total_size' fields to 'limit', 'offset' and 'row_count' respectively PiperOrigin-RevId: 361182102 Source-Author: Google APIs Source-Date: Fri Mar 5 11:01:21 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: d4cd8d96ed6eb5dd7c997aab68a1d6bb0825090c Source-Link: https://github.com/googleapis/googleapis/commit/d4cd8d96ed6eb5dd7c997aab68a1d6bb0825090c chore: upgrade gapic-generator-python to 0.42.2 PiperOrigin-RevId: 361662015 Source-Author: Google APIs Source-Date: Mon Mar 8 14:47:18 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 28a591963253d52ce3a25a918cafbdd9928de8cf Source-Link: https://github.com/googleapis/googleapis/commit/28a591963253d52ce3a25a918cafbdd9928de8cf --- docs/data_v1beta/beta_analytics_data.rst | 5 - .../analytics/data_v1alpha/types/__init__.py | 120 ++++++------ .../beta_analytics_data/async_client.py | 14 +- .../services/beta_analytics_data/client.py | 14 +- .../services/beta_analytics_data/pagers.py | 158 ---------------- .../analytics/data_v1beta/types/__init__.py | 116 ++++++------ .../data_v1beta/types/analytics_data_api.py | 116 +++++------- synth.metadata | 7 +- .../data_v1beta/test_beta_analytics_data.py | 177 +----------------- 9 files changed, 184 insertions(+), 543 deletions(-) delete mode 100644 google/analytics/data_v1beta/services/beta_analytics_data/pagers.py diff --git a/docs/data_v1beta/beta_analytics_data.rst b/docs/data_v1beta/beta_analytics_data.rst index bcdd65e..7bcaa51 100644 --- a/docs/data_v1beta/beta_analytics_data.rst +++ b/docs/data_v1beta/beta_analytics_data.rst @@ -4,8 +4,3 @@ BetaAnalyticsData .. automodule:: google.analytics.data_v1beta.services.beta_analytics_data :members: :inherited-members: - - -.. automodule:: google.analytics.data_v1beta.services.beta_analytics_data.pagers - :members: - :inherited-members: diff --git a/google/analytics/data_v1alpha/types/__init__.py b/google/analytics/data_v1alpha/types/__init__.py index ca30e25..298cbc2 100644 --- a/google/analytics/data_v1alpha/types/__init__.py +++ b/google/analytics/data_v1alpha/types/__init__.py @@ -15,92 +15,92 @@ # limitations under the License. # +from .analytics_data_api import ( + BatchRunPivotReportsRequest, + BatchRunPivotReportsResponse, + BatchRunReportsRequest, + BatchRunReportsResponse, + GetMetadataRequest, + Metadata, + RunPivotReportRequest, + RunPivotReportResponse, + RunRealtimeReportRequest, + RunRealtimeReportResponse, + RunReportRequest, + RunReportResponse, +) from .data import ( + Cohort, + CohortReportSettings, + CohortSpec, + CohortsRange, DateRange, - Entity, Dimension, DimensionExpression, - Metric, + DimensionHeader, + DimensionMetadata, + DimensionValue, + Entity, + Filter, FilterExpression, FilterExpressionList, - Filter, - OrderBy, - Pivot, - CohortSpec, - Cohort, - CohortsRange, - CohortReportSettings, - ResponseMetaData, - DimensionHeader, + Metric, MetricHeader, - PivotHeader, - PivotDimensionHeader, - Row, - DimensionValue, + MetricMetadata, MetricValue, NumericValue, + OrderBy, + Pivot, + PivotDimensionHeader, + PivotHeader, PropertyQuota, QuotaStatus, - DimensionMetadata, - MetricMetadata, + ResponseMetaData, + Row, MetricAggregation, MetricType, ) -from .analytics_data_api import ( - Metadata, - RunReportRequest, - RunReportResponse, - RunPivotReportRequest, - RunPivotReportResponse, - BatchRunReportsRequest, - BatchRunReportsResponse, - BatchRunPivotReportsRequest, - BatchRunPivotReportsResponse, - GetMetadataRequest, - RunRealtimeReportRequest, - RunRealtimeReportResponse, -) __all__ = ( + "BatchRunPivotReportsRequest", + "BatchRunPivotReportsResponse", + "BatchRunReportsRequest", + "BatchRunReportsResponse", + "GetMetadataRequest", + "Metadata", + "RunPivotReportRequest", + "RunPivotReportResponse", + "RunRealtimeReportRequest", + "RunRealtimeReportResponse", + "RunReportRequest", + "RunReportResponse", + "Cohort", + "CohortReportSettings", + "CohortSpec", + "CohortsRange", "DateRange", - "Entity", "Dimension", "DimensionExpression", - "Metric", + "DimensionHeader", + "DimensionMetadata", + "DimensionValue", + "Entity", + "Filter", "FilterExpression", "FilterExpressionList", - "Filter", - "OrderBy", - "Pivot", - "CohortSpec", - "Cohort", - "CohortsRange", - "CohortReportSettings", - "ResponseMetaData", - "DimensionHeader", + "Metric", "MetricHeader", - "PivotHeader", - "PivotDimensionHeader", - "Row", - "DimensionValue", + "MetricMetadata", "MetricValue", "NumericValue", + "OrderBy", + "Pivot", + "PivotDimensionHeader", + "PivotHeader", "PropertyQuota", "QuotaStatus", - "DimensionMetadata", - "MetricMetadata", + "ResponseMetaData", + "Row", "MetricAggregation", "MetricType", - "Metadata", - "RunReportRequest", - "RunReportResponse", - "RunPivotReportRequest", - "RunPivotReportResponse", - "BatchRunReportsRequest", - "BatchRunReportsResponse", - "BatchRunPivotReportsRequest", - "BatchRunPivotReportsResponse", - "GetMetadataRequest", - "RunRealtimeReportRequest", - "RunRealtimeReportResponse", ) 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 523b0f4..a23ad74 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 @@ -28,7 +28,6 @@ from google.auth import credentials # type: ignore from google.oauth2 import service_account # type: ignore -from google.analytics.data_v1beta.services.beta_analytics_data import pagers from google.analytics.data_v1beta.types import analytics_data_api from google.analytics.data_v1beta.types import data @@ -177,7 +176,7 @@ async def run_report( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.RunReportAsyncPager: + ) -> analytics_data_api.RunReportResponse: r"""Returns a customized report of your Google Analytics event data. Reports contain statistics derived from data collected by the Google Analytics tracking code. The @@ -199,12 +198,9 @@ async def run_report( sent along with the request as metadata. Returns: - google.analytics.data_v1beta.services.beta_analytics_data.pagers.RunReportAsyncPager: + google.analytics.data_v1beta.types.RunReportResponse: The response report table corresponding to a request. - Iterating over this object will yield - results and resolve additional pages - automatically. """ # Create or coerce a protobuf request object. @@ -228,12 +224,6 @@ async def run_report( # Send the request. response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.RunReportAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, - ) - # Done; return the response. return response 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 c26aa32..fe5592b 100644 --- a/google/analytics/data_v1beta/services/beta_analytics_data/client.py +++ b/google/analytics/data_v1beta/services/beta_analytics_data/client.py @@ -32,7 +32,6 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -from google.analytics.data_v1beta.services.beta_analytics_data import pagers from google.analytics.data_v1beta.types import analytics_data_api from google.analytics.data_v1beta.types import data @@ -348,7 +347,7 @@ def run_report( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.RunReportPager: + ) -> analytics_data_api.RunReportResponse: r"""Returns a customized report of your Google Analytics event data. Reports contain statistics derived from data collected by the Google Analytics tracking code. The @@ -370,12 +369,9 @@ def run_report( sent along with the request as metadata. Returns: - google.analytics.data_v1beta.services.beta_analytics_data.pagers.RunReportPager: + google.analytics.data_v1beta.types.RunReportResponse: The response report table corresponding to a request. - Iterating over this object will yield - results and resolve additional pages - automatically. """ # Create or coerce a protobuf request object. @@ -400,12 +396,6 @@ def run_report( # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.RunReportPager( - method=rpc, request=request, response=response, metadata=metadata, - ) - # Done; return the response. return response diff --git a/google/analytics/data_v1beta/services/beta_analytics_data/pagers.py b/google/analytics/data_v1beta/services/beta_analytics_data/pagers.py deleted file mode 100644 index 6361325..0000000 --- a/google/analytics/data_v1beta/services/beta_analytics_data/pagers.py +++ /dev/null @@ -1,158 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from typing import ( - Any, - AsyncIterable, - Awaitable, - Callable, - Iterable, - Sequence, - Tuple, - Optional, -) - -from google.analytics.data_v1beta.types import analytics_data_api -from google.analytics.data_v1beta.types import data - - -class RunReportPager: - """A pager for iterating through ``run_report`` requests. - - This class thinly wraps an initial - :class:`google.analytics.data_v1beta.types.RunReportResponse` object, and - provides an ``__iter__`` method to iterate through its - ``dimension_headers`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``RunReport`` requests and continue to iterate - through the ``dimension_headers`` field on the - corresponding responses. - - All the usual :class:`google.analytics.data_v1beta.types.RunReportResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - - def __init__( - self, - method: Callable[..., analytics_data_api.RunReportResponse], - request: analytics_data_api.RunReportRequest, - response: analytics_data_api.RunReportResponse, - *, - metadata: Sequence[Tuple[str, str]] = () - ): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.analytics.data_v1beta.types.RunReportRequest): - The initial request object. - response (google.analytics.data_v1beta.types.RunReportResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = analytics_data_api.RunReportRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterable[analytics_data_api.RunReportResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterable[data.DimensionHeader]: - for page in self.pages: - yield from page.dimension_headers - - def __repr__(self) -> str: - return "{0}<{1!r}>".format(self.__class__.__name__, self._response) - - -class RunReportAsyncPager: - """A pager for iterating through ``run_report`` requests. - - This class thinly wraps an initial - :class:`google.analytics.data_v1beta.types.RunReportResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``dimension_headers`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``RunReport`` requests and continue to iterate - through the ``dimension_headers`` field on the - corresponding responses. - - All the usual :class:`google.analytics.data_v1beta.types.RunReportResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - - def __init__( - self, - method: Callable[..., Awaitable[analytics_data_api.RunReportResponse]], - request: analytics_data_api.RunReportRequest, - response: analytics_data_api.RunReportResponse, - *, - metadata: Sequence[Tuple[str, str]] = () - ): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.analytics.data_v1beta.types.RunReportRequest): - The initial request object. - response (google.analytics.data_v1beta.types.RunReportResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = analytics_data_api.RunReportRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterable[analytics_data_api.RunReportResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - - def __aiter__(self) -> AsyncIterable[data.DimensionHeader]: - async def async_generator(): - async for page in self.pages: - for response in page.dimension_headers: - yield response - - return async_generator() - - def __repr__(self) -> str: - return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/analytics/data_v1beta/types/__init__.py b/google/analytics/data_v1beta/types/__init__.py index 6b5beb8..faa4850 100644 --- a/google/analytics/data_v1beta/types/__init__.py +++ b/google/analytics/data_v1beta/types/__init__.py @@ -15,90 +15,90 @@ # limitations under the License. # +from .analytics_data_api import ( + BatchRunPivotReportsRequest, + BatchRunPivotReportsResponse, + BatchRunReportsRequest, + BatchRunReportsResponse, + GetMetadataRequest, + Metadata, + RunPivotReportRequest, + RunPivotReportResponse, + RunRealtimeReportRequest, + RunRealtimeReportResponse, + RunReportRequest, + RunReportResponse, +) from .data import ( + Cohort, + CohortReportSettings, + CohortSpec, + CohortsRange, DateRange, Dimension, DimensionExpression, - Metric, + DimensionHeader, + DimensionMetadata, + DimensionValue, + Filter, FilterExpression, FilterExpressionList, - Filter, - OrderBy, - Pivot, - CohortSpec, - Cohort, - CohortsRange, - CohortReportSettings, - ResponseMetaData, - DimensionHeader, + Metric, MetricHeader, - PivotHeader, - PivotDimensionHeader, - Row, - DimensionValue, + MetricMetadata, MetricValue, NumericValue, + OrderBy, + Pivot, + PivotDimensionHeader, + PivotHeader, PropertyQuota, QuotaStatus, - DimensionMetadata, - MetricMetadata, + ResponseMetaData, + Row, MetricAggregation, MetricType, ) -from .analytics_data_api import ( - Metadata, - RunReportRequest, - RunReportResponse, - RunPivotReportRequest, - RunPivotReportResponse, - BatchRunReportsRequest, - BatchRunReportsResponse, - BatchRunPivotReportsRequest, - BatchRunPivotReportsResponse, - GetMetadataRequest, - RunRealtimeReportRequest, - RunRealtimeReportResponse, -) __all__ = ( + "BatchRunPivotReportsRequest", + "BatchRunPivotReportsResponse", + "BatchRunReportsRequest", + "BatchRunReportsResponse", + "GetMetadataRequest", + "Metadata", + "RunPivotReportRequest", + "RunPivotReportResponse", + "RunRealtimeReportRequest", + "RunRealtimeReportResponse", + "RunReportRequest", + "RunReportResponse", + "Cohort", + "CohortReportSettings", + "CohortSpec", + "CohortsRange", "DateRange", "Dimension", "DimensionExpression", - "Metric", + "DimensionHeader", + "DimensionMetadata", + "DimensionValue", + "Filter", "FilterExpression", "FilterExpressionList", - "Filter", - "OrderBy", - "Pivot", - "CohortSpec", - "Cohort", - "CohortsRange", - "CohortReportSettings", - "ResponseMetaData", - "DimensionHeader", + "Metric", "MetricHeader", - "PivotHeader", - "PivotDimensionHeader", - "Row", - "DimensionValue", + "MetricMetadata", "MetricValue", "NumericValue", + "OrderBy", + "Pivot", + "PivotDimensionHeader", + "PivotHeader", "PropertyQuota", "QuotaStatus", - "DimensionMetadata", - "MetricMetadata", + "ResponseMetaData", + "Row", "MetricAggregation", "MetricType", - "Metadata", - "RunReportRequest", - "RunReportResponse", - "RunPivotReportRequest", - "RunPivotReportResponse", - "BatchRunReportsRequest", - "BatchRunReportsResponse", - "BatchRunPivotReportsRequest", - "BatchRunPivotReportsResponse", - "GetMetadataRequest", - "RunRealtimeReportRequest", - "RunRealtimeReportResponse", ) diff --git a/google/analytics/data_v1beta/types/analytics_data_api.py b/google/analytics/data_v1beta/types/analytics_data_api.py index b12602b..8f8a10b 100644 --- a/google/analytics/data_v1beta/types/analytics_data_api.py +++ b/google/analytics/data_v1beta/types/analytics_data_api.py @@ -96,31 +96,30 @@ class RunReportRequest(proto.Message): Metrics must be requested to be used in this filter. Dimensions cannot be used in this filter. - page_size (int): - Page size is for paging and specifies maximum number of rows - to return. The API returns a maximum of 200,000 rows per - request, no matter how many you ask for. Page size must be - positive. + offset (int): + The row count of the start row. The first row is counted as + row 0. - The API can also return fewer rows than the requested - ``pageSize``, if there aren't as many dimension values as - the ``pageSize``. For instance, there are fewer than 300 - possible values for the dimension ``country``, so when - reporting on only ``country``, you can't get more than 300 - rows, even if you set ``pageSize`` to a higher value. + When paging, the first request does not specify offset; or + equivalently, sets offset to 0; the first request returns + the first ``limit`` of rows. The second request sets offset + to the ``limit`` of the first request; the second request + returns the second ``limit`` of rows. To learn more about this pagination parameter, see `Pagination `__. - page_token (str): - A continuation token to get the next page of the results. - Adding this to the request will return the next page of rows - after the ``pageToken``. The ``pageToken`` should be the - value returned in the ``nextPageToken`` parameter in the - response. + limit (int): + The number of rows to return. If unspecified, 10,000 rows + are returned. The API returns a maximum of 100,000 rows per + request, no matter how many you ask for. ``limit`` must be + positive. - When paginating, all other parameters specified in - ``RunReportRequest`` must match the call that provided the - page token. + The API can also return fewer rows than the requested + ``limit``, if there aren't as many dimension values as the + ``limit``. For instance, there are fewer than 300 possible + values for the dimension ``country``, so when reporting on + only ``country``, you can't get more than 300 rows, even if + you set ``limit`` to a higher value. To learn more about this pagination parameter, see `Pagination `__. @@ -164,9 +163,9 @@ class RunReportRequest(proto.Message): metric_filter = proto.Field(proto.MESSAGE, number=6, message=data.FilterExpression,) - page_size = proto.Field(proto.INT32, number=7) + offset = proto.Field(proto.INT64, number=7) - page_token = proto.Field(proto.STRING, number=8) + limit = proto.Field(proto.INT64, number=8) metric_aggregations = proto.RepeatedField( proto.ENUM, number=9, enum=data.MetricAggregation, @@ -205,22 +204,14 @@ class RunReportResponse(proto.Message): If requested, the maximum values of metrics. minimums (Sequence[google.analytics.data_v1beta.types.Row]): If requested, the minimum values of metrics. - next_page_token (str): - A token that can be sent as ``pageToken`` in a subsequent - ``RunReportRequest`` call to retrieve the next page of - report rows. If this field is omitted, there are no - subsequent pages of report rows. - - To learn more about this pagination parameter, see - `Pagination `__. - total_size (int): - The total number of rows in the query result. ``totalSize`` + row_count (int): + The total number of rows in the query result. ``rowCount`` is independent of the number of rows returned in the - response, the ``pageSize`` request parameter, and the - ``pageToken`` request parameter. For example if a query - returns 175 rows and includes ``pageSize`` of 50 in the API - request, the response will contain ``totalSize`` of 175 but - only 50 rows. + response, the ``limit`` request parameter, and the + ``offset`` request parameter. For example if a query returns + 175 rows and includes ``limit`` of 50 in the API request, + the response will contain ``rowCount`` of 175 but only 50 + rows. To learn more about this pagination parameter, see `Pagination `__. @@ -231,10 +222,6 @@ class RunReportResponse(proto.Message): including this request. """ - @property - def raw_page(self): - return self - dimension_headers = proto.RepeatedField( proto.MESSAGE, number=1, message=data.DimensionHeader, ) @@ -251,13 +238,11 @@ def raw_page(self): minimums = proto.RepeatedField(proto.MESSAGE, number=6, message=data.Row,) - next_page_token = proto.Field(proto.STRING, number=7) - - total_size = proto.Field(proto.INT32, number=8) + row_count = proto.Field(proto.INT32, number=7) - metadata = proto.Field(proto.MESSAGE, number=9, message=data.ResponseMetaData,) + metadata = proto.Field(proto.MESSAGE, number=8, message=data.ResponseMetaData,) - property_quota = proto.Field(proto.MESSAGE, number=10, message=data.PropertyQuota,) + property_quota = proto.Field(proto.MESSAGE, number=9, message=data.PropertyQuota,) class RunPivotReportRequest(proto.Message): @@ -568,21 +553,18 @@ class RunRealtimeReportRequest(proto.Message): Metrics must be requested to be used in this filter. Dimensions cannot be used in this filter. - page_size (int): - Page size specifies maximum number of rows to return. If - unspecified, up to 10,000 rows are returned. The API returns - a maximum of 100,000 rows per request, no matter how many - you ask for. Page size must be positive. + limit (int): + The number of rows to return. If unspecified, 10,000 rows + are returned. The API returns a maximum of 100,000 rows per + request, no matter how many you ask for. ``limit`` must be + positive. The API can also return fewer rows than the requested - ``pageSize``, if there aren't as many dimension values as - the ``pageSize``. For instance, there are fewer than 300 - possible values for the dimension ``country``, so when - reporting on only ``country``, you can't get more than 300 - rows, even if you set ``pageSize`` to a higher value. - - To learn more about this pagination parameter, see - `Pagination `__. + ``limit``, if there aren't as many dimension values as the + ``limit``. For instance, there are fewer than 300 possible + values for the dimension ``country``, so when reporting on + only ``country``, you can't get more than 300 rows, even if + you set ``limit`` to a higher value. metric_aggregations (Sequence[google.analytics.data_v1beta.types.MetricAggregation]): Aggregation of metrics. Aggregated metric values will be shown in rows where the dimension_values are set to @@ -608,7 +590,7 @@ class RunRealtimeReportRequest(proto.Message): metric_filter = proto.Field(proto.MESSAGE, number=5, message=data.FilterExpression,) - page_size = proto.Field(proto.INT32, number=6) + limit = proto.Field(proto.INT64, number=6) metric_aggregations = proto.RepeatedField( proto.ENUM, number=7, enum=data.MetricAggregation, @@ -642,13 +624,13 @@ class RunRealtimeReportResponse(proto.Message): If requested, the maximum values of metrics. minimums (Sequence[google.analytics.data_v1beta.types.Row]): If requested, the minimum values of metrics. - total_size (int): - The total number of rows in the query result. ``totalSize`` + row_count (int): + The total number of rows in the query result. ``rowCount`` is independent of the number of rows returned in the - response and the ``pageSize`` request parameter. For example - if a query returns 175 rows and includes ``pageSize`` of 50 - in the API request, the response will contain ``totalSize`` - of 175 but only 50 rows. + response and the ``limit`` request parameter. For example if + a query returns 175 rows and includes ``limit`` of 50 in the + API request, the response will contain ``rowCount`` of 175 + but only 50 rows. property_quota (google.analytics.data_v1beta.types.PropertyQuota): This Analytics Property's Realtime quota state including this request. @@ -670,7 +652,7 @@ class RunRealtimeReportResponse(proto.Message): minimums = proto.RepeatedField(proto.MESSAGE, number=6, message=data.Row,) - total_size = proto.Field(proto.INT32, number=7) + row_count = proto.Field(proto.INT32, number=7) property_quota = proto.Field(proto.MESSAGE, number=8, message=data.PropertyQuota,) diff --git a/synth.metadata b/synth.metadata index 2e3e66a..0afde4f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-analytics-data.git", - "sha": "58f834e80510abdcbb49801e2901e1ee44653396" + "sha": "fdebf9b96e915a06fecaeb83c1ca59de077249a8" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "8f117308d5bb55816953a0d6ad1a7d27a69a7d3f", - "internalRef": "361084441" + "sha": "28a591963253d52ce3a25a918cafbdd9928de8cf", + "internalRef": "361662015" } }, { @@ -133,7 +133,6 @@ "google/analytics/data_v1beta/services/beta_analytics_data/__init__.py", "google/analytics/data_v1beta/services/beta_analytics_data/async_client.py", "google/analytics/data_v1beta/services/beta_analytics_data/client.py", - "google/analytics/data_v1beta/services/beta_analytics_data/pagers.py", "google/analytics/data_v1beta/services/beta_analytics_data/transports/__init__.py", "google/analytics/data_v1beta/services/beta_analytics_data/transports/base.py", "google/analytics/data_v1beta/services/beta_analytics_data/transports/grpc.py", 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 e43b775..810069d 100644 --- a/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py +++ b/tests/unit/gapic/data_v1beta/test_beta_analytics_data.py @@ -31,7 +31,6 @@ from google.analytics.data_v1beta.services.beta_analytics_data import ( BetaAnalyticsDataClient, ) -from google.analytics.data_v1beta.services.beta_analytics_data import pagers from google.analytics.data_v1beta.services.beta_analytics_data import transports from google.analytics.data_v1beta.types import analytics_data_api from google.analytics.data_v1beta.types import data @@ -472,9 +471,7 @@ def test_run_report( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.run_report), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = analytics_data_api.RunReportResponse( - next_page_token="next_page_token_value", total_size=1086, - ) + call.return_value = analytics_data_api.RunReportResponse(row_count=992,) response = client.run_report(request) @@ -486,11 +483,9 @@ def test_run_report( # Establish that the response is the type that we expect. - assert isinstance(response, pagers.RunReportPager) - - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, analytics_data_api.RunReportResponse) - assert response.total_size == 1086 + assert response.row_count == 992 def test_run_report_from_dict(): @@ -529,9 +524,7 @@ async def test_run_report_async( with mock.patch.object(type(client.transport.run_report), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - analytics_data_api.RunReportResponse( - next_page_token="next_page_token_value", total_size=1086, - ) + analytics_data_api.RunReportResponse(row_count=992,) ) response = await client.run_report(request) @@ -543,11 +536,9 @@ async def test_run_report_async( assert args[0] == analytics_data_api.RunReportRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.RunReportAsyncPager) - - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, analytics_data_api.RunReportResponse) - assert response.total_size == 1086 + assert response.row_count == 992 @pytest.mark.asyncio @@ -608,152 +599,6 @@ async def test_run_report_field_headers_async(): assert ("x-goog-request-params", "property=property/value",) in kw["metadata"] -def test_run_report_pager(): - client = BetaAnalyticsDataClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.run_report), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - analytics_data_api.RunReportResponse( - dimension_headers=[ - data.DimensionHeader(), - data.DimensionHeader(), - data.DimensionHeader(), - ], - next_page_token="abc", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[], next_page_token="def", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(),], next_page_token="ghi", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(), data.DimensionHeader(),], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("property", ""),)), - ) - pager = client.run_report(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, data.DimensionHeader) for i in results) - - -def test_run_report_pages(): - client = BetaAnalyticsDataClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.run_report), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - analytics_data_api.RunReportResponse( - dimension_headers=[ - data.DimensionHeader(), - data.DimensionHeader(), - data.DimensionHeader(), - ], - next_page_token="abc", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[], next_page_token="def", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(),], next_page_token="ghi", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(), data.DimensionHeader(),], - ), - RuntimeError, - ) - pages = list(client.run_report(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_run_report_async_pager(): - client = BetaAnalyticsDataAsyncClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.run_report), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - analytics_data_api.RunReportResponse( - dimension_headers=[ - data.DimensionHeader(), - data.DimensionHeader(), - data.DimensionHeader(), - ], - next_page_token="abc", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[], next_page_token="def", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(),], next_page_token="ghi", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(), data.DimensionHeader(),], - ), - RuntimeError, - ) - async_pager = await client.run_report(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, data.DimensionHeader) for i in responses) - - -@pytest.mark.asyncio -async def test_run_report_async_pages(): - client = BetaAnalyticsDataAsyncClient(credentials=credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.run_report), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - analytics_data_api.RunReportResponse( - dimension_headers=[ - data.DimensionHeader(), - data.DimensionHeader(), - data.DimensionHeader(), - ], - next_page_token="abc", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[], next_page_token="def", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(),], next_page_token="ghi", - ), - analytics_data_api.RunReportResponse( - dimension_headers=[data.DimensionHeader(), data.DimensionHeader(),], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.run_report(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - def test_run_pivot_report( transport: str = "grpc", request_type=analytics_data_api.RunPivotReportRequest ): @@ -1420,9 +1265,7 @@ def test_run_realtime_report( type(client.transport.run_realtime_report), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = analytics_data_api.RunRealtimeReportResponse( - total_size=1086, - ) + call.return_value = analytics_data_api.RunRealtimeReportResponse(row_count=992,) response = client.run_realtime_report(request) @@ -1436,7 +1279,7 @@ def test_run_realtime_report( assert isinstance(response, analytics_data_api.RunRealtimeReportResponse) - assert response.total_size == 1086 + assert response.row_count == 992 def test_run_realtime_report_from_dict(): @@ -1480,7 +1323,7 @@ async def test_run_realtime_report_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - analytics_data_api.RunRealtimeReportResponse(total_size=1086,) + analytics_data_api.RunRealtimeReportResponse(row_count=992,) ) response = await client.run_realtime_report(request) @@ -1494,7 +1337,7 @@ async def test_run_realtime_report_async( # Establish that the response is the type that we expect. assert isinstance(response, analytics_data_api.RunRealtimeReportResponse) - assert response.total_size == 1086 + assert response.row_count == 992 @pytest.mark.asyncio From 22c343a52f75c8dc9bde99bb15af694a374298ae Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 16 Mar 2021 07:46:00 -0700 Subject: [PATCH 5/6] chore: add pre-commit-config to renovate ignore paths (#48) Disable renovate PRs on the .pre-commit-config.yaml which is templated from synthtool. https://docs.renovatebot.com/configuration-options/#ignorepaths Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Source-Date: Mon Mar 15 09:05:39 2021 -0600 Source-Repo: googleapis/synthtool Source-Sha: 2c54c473779ea731128cea61a3a6c975a08a5378 Source-Link: https://github.com/googleapis/synthtool/commit/2c54c473779ea731128cea61a3a6c975a08a5378 --- renovate.json | 3 ++- synth.metadata | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/renovate.json b/renovate.json index 4fa9493..f08bc22 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,6 @@ { "extends": [ "config:base", ":preserveSemverRanges" - ] + ], + "ignorePaths": [".pre-commit-config.yaml"] } diff --git a/synth.metadata b/synth.metadata index 0afde4f..509cf11 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-analytics-data.git", - "sha": "fdebf9b96e915a06fecaeb83c1ca59de077249a8" + "sha": "8fd57a340b7e052dc9c4d6c33882add75405eb8b" } }, { @@ -19,14 +19,14 @@ "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0780323da96d5a53925fe0547757181fe76e8f1e" + "sha": "2c54c473779ea731128cea61a3a6c975a08a5378" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "0780323da96d5a53925fe0547757181fe76e8f1e" + "sha": "2c54c473779ea731128cea61a3a6c975a08a5378" } } ], From e7fa3bd5817a51e852b47c427f598ef02f935437 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 16 Mar 2021 09:46:11 -0600 Subject: [PATCH 6/6] chore: release 0.4.1 (#45) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ setup.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d87aa2..48d99fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### [0.4.1](https://www.github.com/googleapis/python-analytics-data/compare/v0.4.0...v0.4.1) (2021-03-16) + + +### Bug Fixes + +* fix from_service_account_info for async clients ([#44](https://www.github.com/googleapis/python-analytics-data/issues/44)) ([fdebf9b](https://www.github.com/googleapis/python-analytics-data/commit/fdebf9b96e915a06fecaeb83c1ca59de077249a8)) +* **v1beta:** (BREAKING) rename the 'page_size', 'page_token', 'total_size' fields to 'limit', 'offset' and 'row_count' respectively ([8fd57a3](https://www.github.com/googleapis/python-analytics-data/commit/8fd57a340b7e052dc9c4d6c33882add75405eb8b)) + ## [0.4.0](https://www.github.com/googleapis/python-analytics-data/compare/v0.3.0...v0.4.0) (2021-02-25) diff --git a/setup.py b/setup.py index e18e447..012b229 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "0.4.0" +version = "0.4.1" package_root = os.path.abspath(os.path.dirname(__file__))