diff --git a/.flake8 b/.flake8 index 29227d4cf4..2e43874986 100644 --- a/.flake8 +++ b/.flake8 @@ -16,7 +16,7 @@ # Generated by synthtool. DO NOT EDIT! [flake8] -ignore = E203, E266, E501, W503 +ignore = E203, E231, E266, E501, W503 exclude = # Exclude generated code. **/proto/** diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 8cb43804d9..51b61ba529 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,4 +13,4 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 + digest: sha256:266a3407f0bb34374f49b6556ee20ee819374587246dcc19405b502ec70113b6 diff --git a/.github/auto-label.yaml b/.github/auto-label.yaml new file mode 100644 index 0000000000..41bff0b537 --- /dev/null +++ b/.github/auto-label.yaml @@ -0,0 +1,15 @@ +# Copyright 2022 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. +requestsize: + enabled: true diff --git a/.github/release-please.yml b/.github/release-please.yml index 466597e5b1..5161ab347c 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1,2 +1,14 @@ releaseType: python handleGHRelease: true +# NOTE: this section is generated by synthtool.languages.python +# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py +branches: +- branch: v2 + handleGHRelease: true + releaseType: python +- branch: v1 + handleGHRelease: true + releaseType: python +- branch: v0 + handleGHRelease: true + releaseType: python diff --git a/.github/workflows/integration-tests-against-emulator.yaml b/.github/workflows/integration-tests-against-emulator.yaml index 7438f8f0a9..3c8b1c5080 100644 --- a/.github/workflows/integration-tests-against-emulator.yaml +++ b/.github/workflows/integration-tests-against-emulator.yaml @@ -17,9 +17,9 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: 3.8 - name: Install nox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62eb5a77d9..46d237160f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.3.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e84502a3b..70a1735bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,28 @@ [1]: https://pypi.org/project/google-cloud-spanner/#history +## [3.14.0](https://github.com/googleapis/python-spanner/compare/v3.13.0...v3.14.0) (2022-04-20) + + +### Features + +* add support for Cross region backup proto changes ([#691](https://github.com/googleapis/python-spanner/issues/691)) ([8ac62cb](https://github.com/googleapis/python-spanner/commit/8ac62cb83ee5525d6233dcc34919dcbf9471461b)) +* add support for spanner copy backup feature ([#600](https://github.com/googleapis/python-spanner/issues/600)) ([97faf6c](https://github.com/googleapis/python-spanner/commit/97faf6c11f985f128446bc7d9e99a22362bd1bc1)) +* AuditConfig for IAM v1 ([7642eba](https://github.com/googleapis/python-spanner/commit/7642eba1d9c66525ea1ca6f36dd91c759ed3cbde)) + + +### Bug Fixes + +* add NOT_FOUND error check in __exit__ method of SessionCheckout. ([#718](https://github.com/googleapis/python-spanner/issues/718)) ([265e207](https://github.com/googleapis/python-spanner/commit/265e20711510aafc956552e9684ab7a39074bf70)) +* **deps:** require google-api-core>=1.31.5, >=2.3.2 ([#685](https://github.com/googleapis/python-spanner/issues/685)) ([7a46a27](https://github.com/googleapis/python-spanner/commit/7a46a27bacbdcb1e72888bd93dfce93c439ceae2)) +* **deps:** require grpc-google-iam-v1 >=0.12.4 ([7642eba](https://github.com/googleapis/python-spanner/commit/7642eba1d9c66525ea1ca6f36dd91c759ed3cbde)) +* **deps:** require proto-plus>=1.15.0 ([7a46a27](https://github.com/googleapis/python-spanner/commit/7a46a27bacbdcb1e72888bd93dfce93c439ceae2)) + + +### Documentation + +* add generated snippets ([#680](https://github.com/googleapis/python-spanner/issues/680)) ([f21dac4](https://github.com/googleapis/python-spanner/commit/f21dac4c47cb6a6a85fd282b8e5de966b467b1b6)) + ## [3.13.0](https://github.com/googleapis/python-spanner/compare/v3.12.1...v3.13.0) (2022-02-04) diff --git a/docs/conf.py b/docs/conf.py index 6410a1a2ad..96337defe2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -361,7 +361,10 @@ intersphinx_mapping = { "python": ("https://python.readthedocs.org/en/latest/", None), "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), "grpc": ("https://grpc.github.io/grpc/python/", None), "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), diff --git a/google/cloud/spanner_admin_database_v1/__init__.py b/google/cloud/spanner_admin_database_v1/__init__.py index f7d3a4f557..ee52bda123 100644 --- a/google/cloud/spanner_admin_database_v1/__init__.py +++ b/google/cloud/spanner_admin_database_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,9 @@ from .types.backup import Backup from .types.backup import BackupInfo +from .types.backup import CopyBackupEncryptionConfig +from .types.backup import CopyBackupMetadata +from .types.backup import CopyBackupRequest from .types.backup import CreateBackupEncryptionConfig from .types.backup import CreateBackupMetadata from .types.backup import CreateBackupRequest @@ -57,6 +60,9 @@ "DatabaseAdminAsyncClient", "Backup", "BackupInfo", + "CopyBackupEncryptionConfig", + "CopyBackupMetadata", + "CopyBackupRequest", "CreateBackupEncryptionConfig", "CreateBackupMetadata", "CreateBackupRequest", diff --git a/google/cloud/spanner_admin_database_v1/gapic_metadata.json b/google/cloud/spanner_admin_database_v1/gapic_metadata.json index 1460097dc3..f7272318ef 100644 --- a/google/cloud/spanner_admin_database_v1/gapic_metadata.json +++ b/google/cloud/spanner_admin_database_v1/gapic_metadata.json @@ -10,6 +10,11 @@ "grpc": { "libraryClient": "DatabaseAdminClient", "rpcs": { + "CopyBackup": { + "methods": [ + "copy_backup" + ] + }, "CreateBackup": { "methods": [ "create_backup" @@ -100,6 +105,11 @@ "grpc-async": { "libraryClient": "DatabaseAdminAsyncClient", "rpcs": { + "CopyBackup": { + "methods": [ + "copy_backup" + ] + }, "CreateBackup": { "methods": [ "create_backup" diff --git a/google/cloud/spanner_admin_database_v1/services/__init__.py b/google/cloud/spanner_admin_database_v1/services/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/google/cloud/spanner_admin_database_v1/services/__init__.py +++ b/google/cloud/spanner_admin_database_v1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py b/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py index abe449ebfa..6fcf1b82e7 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py b/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py index e4316c170b..c5d38710bf 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -242,6 +242,26 @@ async def list_databases( ) -> pagers.ListDatabasesAsyncPager: r"""Lists Cloud Spanner databases. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]): The request object. The request for @@ -311,12 +331,20 @@ async def list_databases( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatabasesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -343,6 +371,30 @@ async def create_database( is [Database][google.spanner.admin.database.v1.Database], if successful. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]): The request object. The request for @@ -416,7 +468,12 @@ async def create_database( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -440,6 +497,25 @@ async def get_database( ) -> spanner_database_admin.Database: r"""Gets the state of a Cloud Spanner database. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = client.get_database(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]): The request object. The request for @@ -504,7 +580,12 @@ async def get_database( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -529,6 +610,30 @@ async def update_database_ddl( [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. The operation has no response. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value_1', 'statements_value_2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]): The request object. Enqueues the given DDL statements to @@ -631,7 +736,12 @@ async def update_database_ddl( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -658,6 +768,22 @@ async def drop_database( ``expire_time``. Note: Cloud Spanner might continue to accept requests for a few seconds after the database has been deleted. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + client.drop_database(request=request) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]): The request object. The request for @@ -716,7 +842,10 @@ async def drop_database( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def get_database_ddl( @@ -733,6 +862,25 @@ async def get_database_ddl( schema updates, those may be queried using the [Operations][google.longrunning.Operations] API. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = client.get_database_ddl(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]): The request object. The request for @@ -799,7 +947,12 @@ async def get_database_ddl( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -823,6 +976,26 @@ async def set_iam_policy( permission on [resource][google.iam.v1.SetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` @@ -844,21 +1017,26 @@ async def set_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -873,17 +1051,17 @@ async def set_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -894,11 +1072,12 @@ async def set_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -916,7 +1095,9 @@ async def set_iam_policy( if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) elif not request: - request = iam_policy_pb2.SetIamPolicyRequest(resource=resource,) + request = iam_policy_pb2.SetIamPolicyRequest( + resource=resource, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -933,7 +1114,12 @@ async def set_iam_policy( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -958,6 +1144,26 @@ async def get_iam_policy( permission on [resource][google.iam.v1.GetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` @@ -979,21 +1185,26 @@ async def get_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1008,17 +1219,17 @@ async def get_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1029,11 +1240,12 @@ async def get_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1051,7 +1263,9 @@ async def get_iam_policy( if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) elif not request: - request = iam_policy_pb2.GetIamPolicyRequest(resource=resource,) + request = iam_policy_pb2.GetIamPolicyRequest( + resource=resource, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1078,7 +1292,12 @@ async def get_iam_policy( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1104,6 +1323,27 @@ async def test_iam_permissions( in a NOT_FOUND error if the user has ``spanner.backups.list`` permission on the containing instance. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for @@ -1152,7 +1392,8 @@ async def test_iam_permissions( request = iam_policy_pb2.TestIamPermissionsRequest(**request) elif not request: request = iam_policy_pb2.TestIamPermissionsRequest( - resource=resource, permissions=permissions, + resource=resource, + permissions=permissions, ) # Wrap the RPC method; this adds retry and timeout information, @@ -1170,7 +1411,12 @@ async def test_iam_permissions( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1200,6 +1446,30 @@ async def create_backup( backup creation per database. Backup creation of different databases can run concurrently. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]): The request object. The request for @@ -1281,7 +1551,12 @@ async def create_backup( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1294,6 +1569,172 @@ async def create_backup( # Done; return the response. return response + async def copy_backup( + self, + request: Union[backup.CopyBackupRequest, dict] = None, + *, + parent: str = None, + backup_id: str = None, + source_backup: str = None, + expire_time: timestamp_pb2.Timestamp = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]): + The request object. The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + parent (:class:`str`): + Required. The name of the destination instance that will + contain the backup copy. Values are of the form: + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup_id (:class:`str`): + Required. The id of the backup copy. The ``backup_id`` + appended to ``parent`` forms the full backup_uri of the + form + ``projects//instances//backups/``. + + This corresponds to the ``backup_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_backup (:class:`str`): + Required. The source backup to be copied. The source + backup needs to be in READY state for it to be copied. + Once CopyBackup is in progress, the source backup cannot + be deleted or cleaned up on expiration until CopyBackup + is finished. Values are of the form: + ``projects//instances//backups/``. + + This corresponds to the ``source_backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + expire_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): + Required. The expiration time of the backup in + microsecond granularity. The expiration time must be at + least 6 hours and at most 366 days from the + ``create_time`` of the source backup. Once the + ``expire_time`` has passed, the backup is eligible to be + automatically deleted by Cloud Spanner to free the + resources used by the backup. + + This corresponds to the ``expire_time`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + 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.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Backup` + A backup of a Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, backup_id, source_backup, expire_time]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = backup.CopyBackupRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if backup_id is not None: + request.backup_id = backup_id + if source_backup is not None: + request.source_backup = source_backup + if expire_time is not None: + request.expire_time = expire_time + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.copy_backup, + default_timeout=3600.0, + 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((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + backup.Backup, + metadata_type=backup.CopyBackupMetadata, + ) + + # Done; return the response. + return response + async def get_backup( self, request: Union[backup.GetBackupRequest, dict] = None, @@ -1306,6 +1747,25 @@ async def get_backup( r"""Gets metadata on a pending or completed [Backup][google.spanner.admin.database.v1.Backup]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = client.get_backup(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]): The request object. The request for @@ -1369,7 +1829,12 @@ async def get_backup( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1387,6 +1852,24 @@ async def update_backup( r"""Updates a pending or completed [Backup][google.spanner.admin.database.v1.Backup]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = client.update_backup(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]): The request object. The request for @@ -1470,7 +1953,12 @@ async def update_backup( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1487,6 +1975,22 @@ async def delete_backup( r"""Deletes a pending or completed [Backup][google.spanner.admin.database.v1.Backup]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + client.delete_backup(request=request) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]): The request object. The request for @@ -1548,7 +2052,10 @@ async def delete_backup( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def list_backups( @@ -1564,6 +2071,26 @@ async def list_backups( ordered by ``create_time`` in descending order, starting from the most recent ``create_time``. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]): The request object. The request for @@ -1632,12 +2159,20 @@ async def list_backups( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBackupsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1674,6 +2209,31 @@ async def restore_database( without waiting for the optimize operation associated with the first restore to complete. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]): The request object. The request for @@ -1757,7 +2317,12 @@ async def restore_database( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1792,6 +2357,26 @@ async def list_database_operations( completed/failed/canceled within the last 7 days, and pending operations. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]): The request object. The request for @@ -1861,12 +2446,20 @@ async def list_database_operations( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatabaseOperationsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1894,6 +2487,26 @@ async def list_backup_operations( ``operation.metadata.value.progress.start_time`` in descending order starting from the most recently started operation. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]): The request object. The request for @@ -1963,12 +2576,20 @@ async def list_backup_operations( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBackupOperationsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/client.py b/google/cloud/spanner_admin_database_v1/services/database_admin/client.py index aca0ee8a43..19bbf83097 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/client.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib @@ -64,7 +64,10 @@ class DatabaseAdminClientMeta(type): _transport_registry["grpc"] = DatabaseAdminGrpcTransport _transport_registry["grpc_asyncio"] = DatabaseAdminGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[DatabaseAdminTransport]: + def get_transport_class( + cls, + label: str = None, + ) -> Type[DatabaseAdminTransport]: """Returns an appropriate transport class. Args: @@ -177,10 +180,16 @@ def transport(self) -> DatabaseAdminTransport: return self._transport @staticmethod - def backup_path(project: str, instance: str, backup: str,) -> str: + def backup_path( + project: str, + instance: str, + backup: str, + ) -> str: """Returns a fully-qualified backup string.""" return "projects/{project}/instances/{instance}/backups/{backup}".format( - project=project, instance=instance, backup=backup, + project=project, + instance=instance, + backup=backup, ) @staticmethod @@ -194,7 +203,10 @@ def parse_backup_path(path: str) -> Dict[str, str]: @staticmethod def crypto_key_path( - project: str, location: str, key_ring: str, crypto_key: str, + project: str, + location: str, + key_ring: str, + crypto_key: str, ) -> str: """Returns a fully-qualified crypto_key string.""" return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format( @@ -240,10 +252,16 @@ def parse_crypto_key_version_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def database_path(project: str, instance: str, database: str,) -> str: + def database_path( + project: str, + instance: str, + database: str, + ) -> str: """Returns a fully-qualified database string.""" return "projects/{project}/instances/{instance}/databases/{database}".format( - project=project, instance=instance, database=database, + project=project, + instance=instance, + database=database, ) @staticmethod @@ -256,10 +274,14 @@ def parse_database_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def instance_path(project: str, instance: str,) -> str: + def instance_path( + project: str, + instance: str, + ) -> str: """Returns a fully-qualified instance string.""" return "projects/{project}/instances/{instance}".format( - project=project, instance=instance, + project=project, + instance=instance, ) @staticmethod @@ -269,7 +291,9 @@ def parse_instance_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -282,9 +306,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -293,9 +321,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -304,9 +336,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -315,10 +351,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -503,6 +543,26 @@ def list_databases( ) -> pagers.ListDatabasesPager: r"""Lists Cloud Spanner databases. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]): The request object. The request for @@ -562,12 +622,20 @@ def list_databases( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatabasesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -594,6 +662,30 @@ def create_database( is [Database][google.spanner.admin.database.v1.Database], if successful. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]): The request object. The request for @@ -667,7 +759,12 @@ def create_database( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -691,6 +788,25 @@ def get_database( ) -> spanner_database_admin.Database: r"""Gets the state of a Cloud Spanner database. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = client.get_database(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]): The request object. The request for @@ -745,7 +861,12 @@ def get_database( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -770,6 +891,30 @@ def update_database_ddl( [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. The operation has no response. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value_1', 'statements_value_2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]): The request object. Enqueues the given DDL statements to @@ -862,7 +1007,12 @@ def update_database_ddl( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -889,6 +1039,22 @@ def drop_database( ``expire_time``. Note: Cloud Spanner might continue to accept requests for a few seconds after the database has been deleted. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + client.drop_database(request=request) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]): The request object. The request for @@ -937,7 +1103,10 @@ def drop_database( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def get_database_ddl( @@ -954,6 +1123,25 @@ def get_database_ddl( schema updates, those may be queried using the [Operations][google.longrunning.Operations] API. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = client.get_database_ddl(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]): The request object. The request for @@ -1010,7 +1198,12 @@ def get_database_ddl( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1034,6 +1227,26 @@ def set_iam_policy( permission on [resource][google.iam.v1.SetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` @@ -1055,21 +1268,26 @@ def set_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1084,17 +1302,17 @@ def set_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1105,11 +1323,12 @@ def set_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1143,7 +1362,12 @@ def set_iam_policy( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1168,6 +1392,26 @@ def get_iam_policy( permission on [resource][google.iam.v1.GetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` @@ -1189,21 +1433,26 @@ def get_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1218,17 +1467,17 @@ def get_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1239,11 +1488,12 @@ def get_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1277,7 +1527,12 @@ def get_iam_policy( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1303,6 +1558,27 @@ def test_iam_permissions( in a NOT_FOUND error if the user has ``spanner.backups.list`` permission on the containing instance. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for @@ -1368,7 +1644,12 @@ def test_iam_permissions( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1398,6 +1679,30 @@ def create_backup( backup creation per database. Backup creation of different databases can run concurrently. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]): The request object. The request for @@ -1479,7 +1784,12 @@ def create_backup( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1492,6 +1802,172 @@ def create_backup( # Done; return the response. return response + def copy_backup( + self, + request: Union[backup.CopyBackupRequest, dict] = None, + *, + parent: str = None, + backup_id: str = None, + source_backup: str = None, + expire_time: timestamp_pb2.Timestamp = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]): + The request object. The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + parent (str): + Required. The name of the destination instance that will + contain the backup copy. Values are of the form: + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup_id (str): + Required. The id of the backup copy. The ``backup_id`` + appended to ``parent`` forms the full backup_uri of the + form + ``projects//instances//backups/``. + + This corresponds to the ``backup_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_backup (str): + Required. The source backup to be copied. The source + backup needs to be in READY state for it to be copied. + Once CopyBackup is in progress, the source backup cannot + be deleted or cleaned up on expiration until CopyBackup + is finished. Values are of the form: + ``projects//instances//backups/``. + + This corresponds to the ``source_backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + expire_time (google.protobuf.timestamp_pb2.Timestamp): + Required. The expiration time of the backup in + microsecond granularity. The expiration time must be at + least 6 hours and at most 366 days from the + ``create_time`` of the source backup. Once the + ``expire_time`` has passed, the backup is eligible to be + automatically deleted by Cloud Spanner to free the + resources used by the backup. + + This corresponds to the ``expire_time`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + 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.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Backup` + A backup of a Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, backup_id, source_backup, expire_time]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a backup.CopyBackupRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, backup.CopyBackupRequest): + request = backup.CopyBackupRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if backup_id is not None: + request.backup_id = backup_id + if source_backup is not None: + request.source_backup = source_backup + if expire_time is not None: + request.expire_time = expire_time + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.copy_backup] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + backup.Backup, + metadata_type=backup.CopyBackupMetadata, + ) + + # Done; return the response. + return response + def get_backup( self, request: Union[backup.GetBackupRequest, dict] = None, @@ -1504,6 +1980,25 @@ def get_backup( r"""Gets metadata on a pending or completed [Backup][google.spanner.admin.database.v1.Backup]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = client.get_backup(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]): The request object. The request for @@ -1557,7 +2052,12 @@ def get_backup( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1575,6 +2075,24 @@ def update_backup( r"""Updates a pending or completed [Backup][google.spanner.admin.database.v1.Backup]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = client.update_backup(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]): The request object. The request for @@ -1648,7 +2166,12 @@ def update_backup( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1665,6 +2188,22 @@ def delete_backup( r"""Deletes a pending or completed [Backup][google.spanner.admin.database.v1.Backup]. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + client.delete_backup(request=request) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]): The request object. The request for @@ -1716,7 +2255,10 @@ def delete_backup( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def list_backups( @@ -1732,6 +2274,26 @@ def list_backups( ordered by ``create_time`` in descending order, starting from the most recent ``create_time``. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]): The request object. The request for @@ -1790,12 +2352,20 @@ def list_backups( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBackupsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1832,6 +2402,31 @@ def restore_database( without waiting for the optimize operation associated with the first restore to complete. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]): The request object. The request for @@ -1915,7 +2510,12 @@ def restore_database( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1950,6 +2550,26 @@ def list_database_operations( completed/failed/canceled within the last 7 days, and pending operations. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]): The request object. The request for @@ -2011,12 +2631,20 @@ def list_database_operations( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatabaseOperationsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2044,6 +2672,26 @@ def list_backup_operations( ``operation.metadata.value.progress.start_time`` in descending order starting from the most recently started operation. + .. code-block:: python + + from google.cloud import spanner_admin_database_v1 + + def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]): The request object. The request for @@ -2103,12 +2751,20 @@ def list_backup_operations( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBackupOperationsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py b/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py index a14ed07855..ed4bd6ba5d 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py index 743a749bfa..8b203ec615 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py index 4869fd03d5..1a93ed842a 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -90,6 +90,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -146,7 +147,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.create_database: gapic_v1.method.wrap_method( - self.create_database, default_timeout=3600.0, client_info=client_info, + self.create_database, + default_timeout=3600.0, + client_info=client_info, ), self.get_database: gapic_v1.method.wrap_method( self.get_database, @@ -209,7 +212,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.set_iam_policy: gapic_v1.method.wrap_method( - self.set_iam_policy, default_timeout=30.0, client_info=client_info, + self.set_iam_policy, + default_timeout=30.0, + client_info=client_info, ), self.get_iam_policy: gapic_v1.method.wrap_method( self.get_iam_policy, @@ -232,7 +237,14 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.create_backup: gapic_v1.method.wrap_method( - self.create_backup, default_timeout=3600.0, client_info=client_info, + self.create_backup, + default_timeout=3600.0, + client_info=client_info, + ), + self.copy_backup: gapic_v1.method.wrap_method( + self.copy_backup, + default_timeout=3600.0, + client_info=client_info, ), self.get_backup: gapic_v1.method.wrap_method( self.get_backup, @@ -295,7 +307,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.restore_database: gapic_v1.method.wrap_method( - self.restore_database, default_timeout=3600.0, client_info=client_info, + self.restore_database, + default_timeout=3600.0, + client_info=client_info, ), self.list_database_operations: gapic_v1.method.wrap_method( self.list_database_operations, @@ -332,9 +346,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -444,6 +458,15 @@ def create_backup( ]: raise NotImplementedError() + @property + def copy_backup( + self, + ) -> Callable[ + [backup.CopyBackupRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def get_backup( self, @@ -511,5 +534,9 @@ def list_backup_operations( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("DatabaseAdminTransport",) diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py index b96319cfdf..18e9341dca 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -239,8 +239,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -593,6 +592,44 @@ def create_backup( ) return self._stubs["create_backup"] + @property + def copy_backup( + self, + ) -> Callable[[backup.CopyBackupRequest], operations_pb2.Operation]: + r"""Return a callable for the copy backup method over gRPC. + + Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + Returns: + Callable[[~.CopyBackupRequest], + ~.Operation]: + 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 "copy_backup" not in self._stubs: + self._stubs["copy_backup"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.database.v1.DatabaseAdmin/CopyBackup", + request_serializer=backup.CopyBackupRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["copy_backup"] + @property def get_backup(self) -> Callable[[backup.GetBackupRequest], backup.Backup]: r"""Return a callable for the get backup method over gRPC. @@ -824,5 +861,9 @@ def list_backup_operations( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("DatabaseAdminGrpcTransport",) diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py index 62c804a2e7..2a3200a882 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -604,6 +604,44 @@ def create_backup( ) return self._stubs["create_backup"] + @property + def copy_backup( + self, + ) -> Callable[[backup.CopyBackupRequest], Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the copy backup method over gRPC. + + Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + Returns: + Callable[[~.CopyBackupRequest], + Awaitable[~.Operation]]: + 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 "copy_backup" not in self._stubs: + self._stubs["copy_backup"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.database.v1.DatabaseAdmin/CopyBackup", + request_serializer=backup.CopyBackupRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["copy_backup"] + @property def get_backup( self, diff --git a/google/cloud/spanner_admin_database_v1/types/__init__.py b/google/cloud/spanner_admin_database_v1/types/__init__.py index f671adc0cf..8d4b5f4094 100644 --- a/google/cloud/spanner_admin_database_v1/types/__init__.py +++ b/google/cloud/spanner_admin_database_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,9 @@ from .backup import ( Backup, BackupInfo, + CopyBackupEncryptionConfig, + CopyBackupMetadata, + CopyBackupRequest, CreateBackupEncryptionConfig, CreateBackupMetadata, CreateBackupRequest, @@ -58,6 +61,9 @@ __all__ = ( "Backup", "BackupInfo", + "CopyBackupEncryptionConfig", + "CopyBackupMetadata", + "CopyBackupRequest", "CreateBackupEncryptionConfig", "CreateBackupMetadata", "CreateBackupRequest", diff --git a/google/cloud/spanner_admin_database_v1/types/backup.py b/google/cloud/spanner_admin_database_v1/types/backup.py index c27a5a5f31..dd42c409b9 100644 --- a/google/cloud/spanner_admin_database_v1/types/backup.py +++ b/google/cloud/spanner_admin_database_v1/types/backup.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,6 +27,8 @@ "Backup", "CreateBackupRequest", "CreateBackupMetadata", + "CopyBackupRequest", + "CopyBackupMetadata", "UpdateBackupRequest", "GetBackupRequest", "DeleteBackupRequest", @@ -36,6 +38,7 @@ "ListBackupOperationsResponse", "BackupInfo", "CreateBackupEncryptionConfig", + "CopyBackupEncryptionConfig", }, ) @@ -107,6 +110,23 @@ class Backup(proto.Message): database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): Output only. The database dialect information for the backup. + referencing_backups (Sequence[str]): + Output only. The names of the destination backups being + created by copying this source backup. The backup names are + of the form + ``projects//instances//backups/``. + Referencing backups may exist in different instances. The + existence of any referencing backup prevents the backup from + being deleted. When the copy operation is done (either + successfully completed or cancelled or the destination + backup is deleted), the reference to the backup is removed. + max_expire_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The max allowed expiration time of the backup, + with microseconds granularity. A backup's expiration time + can be configured in multiple APIs: CreateBackup, + UpdateBackup, CopyBackup. When updating or copying an + existing backup, the expiration time specified must be less + than ``Backup.max_expire_time``. """ class State(proto.Enum): @@ -115,20 +135,61 @@ class State(proto.Enum): CREATING = 1 READY = 2 - database = proto.Field(proto.STRING, number=2,) + database = proto.Field( + proto.STRING, + number=2, + ) version_time = proto.Field( - proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp, - ) - expire_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - size_bytes = proto.Field(proto.INT64, number=5,) - state = proto.Field(proto.ENUM, number=6, enum=State,) - referencing_databases = proto.RepeatedField(proto.STRING, number=7,) + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) + expire_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + size_bytes = proto.Field( + proto.INT64, + number=5, + ) + state = proto.Field( + proto.ENUM, + number=6, + enum=State, + ) + referencing_databases = proto.RepeatedField( + proto.STRING, + number=7, + ) encryption_info = proto.Field( - proto.MESSAGE, number=8, message=common.EncryptionInfo, + proto.MESSAGE, + number=8, + message=common.EncryptionInfo, + ) + database_dialect = proto.Field( + proto.ENUM, + number=10, + enum=common.DatabaseDialect, + ) + referencing_backups = proto.RepeatedField( + proto.STRING, + number=11, + ) + max_expire_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, ) - database_dialect = proto.Field(proto.ENUM, number=10, enum=common.DatabaseDialect,) class CreateBackupRequest(proto.Message): @@ -159,11 +220,23 @@ class CreateBackupRequest(proto.Message): = ``USE_DATABASE_ENCRYPTION``. """ - parent = proto.Field(proto.STRING, number=1,) - backup_id = proto.Field(proto.STRING, number=2,) - backup = proto.Field(proto.MESSAGE, number=3, message="Backup",) + parent = proto.Field( + proto.STRING, + number=1, + ) + backup_id = proto.Field( + proto.STRING, + number=2, + ) + backup = proto.Field( + proto.MESSAGE, + number=3, + message="Backup", + ) encryption_config = proto.Field( - proto.MESSAGE, number=4, message="CreateBackupEncryptionConfig", + proto.MESSAGE, + number=4, + message="CreateBackupEncryptionConfig", ) @@ -198,10 +271,138 @@ class CreateBackupMetadata(proto.Message): 1, corresponding to ``Code.CANCELLED``. """ - name = proto.Field(proto.STRING, number=1,) - database = proto.Field(proto.STRING, number=2,) - progress = proto.Field(proto.MESSAGE, number=3, message=common.OperationProgress,) - cancel_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + database = proto.Field( + proto.STRING, + number=2, + ) + progress = proto.Field( + proto.MESSAGE, + number=3, + message=common.OperationProgress, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +class CopyBackupRequest(proto.Message): + r"""The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + + Attributes: + parent (str): + Required. The name of the destination instance that will + contain the backup copy. Values are of the form: + ``projects//instances/``. + backup_id (str): + Required. The id of the backup copy. The ``backup_id`` + appended to ``parent`` forms the full backup_uri of the form + ``projects//instances//backups/``. + source_backup (str): + Required. The source backup to be copied. The source backup + needs to be in READY state for it to be copied. Once + CopyBackup is in progress, the source backup cannot be + deleted or cleaned up on expiration until CopyBackup is + finished. Values are of the form: + ``projects//instances//backups/``. + expire_time (google.protobuf.timestamp_pb2.Timestamp): + Required. The expiration time of the backup in microsecond + granularity. The expiration time must be at least 6 hours + and at most 366 days from the ``create_time`` of the source + backup. Once the ``expire_time`` has passed, the backup is + eligible to be automatically deleted by Cloud Spanner to + free the resources used by the backup. + encryption_config (google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig): + Optional. The encryption configuration used to encrypt the + backup. If this field is not specified, the backup will use + the same encryption configuration as the source backup by + default, namely + [encryption_type][google.spanner.admin.database.v1.CopyBackupEncryptionConfig.encryption_type] + = ``USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + backup_id = proto.Field( + proto.STRING, + number=2, + ) + source_backup = proto.Field( + proto.STRING, + number=3, + ) + expire_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + encryption_config = proto.Field( + proto.MESSAGE, + number=5, + message="CopyBackupEncryptionConfig", + ) + + +class CopyBackupMetadata(proto.Message): + r"""Metadata type for the google.longrunning.Operation returned by + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + + Attributes: + name (str): + The name of the backup being created through the copy + operation. Values are of the form + ``projects//instances//backups/``. + source_backup (str): + The name of the source backup that is being copied. Values + are of the form + ``projects//instances//backups/``. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which cancellation of CopyBackup operation was + received. + [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] + starts asynchronous cancellation on a long-running + operation. The server makes a best effort to cancel the + operation, but success is not guaranteed. Clients can use + [Operations.GetOperation][google.longrunning.Operations.GetOperation] + or other methods to check whether the cancellation succeeded + or whether the operation completed despite cancellation. On + successful cancellation, the operation is not deleted; + instead, it becomes an operation with an + [Operation.error][google.longrunning.Operation.error] value + with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + source_backup = proto.Field( + proto.STRING, + number=2, + ) + progress = proto.Field( + proto.MESSAGE, + number=3, + message=common.OperationProgress, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) class UpdateBackupRequest(proto.Message): @@ -225,9 +426,15 @@ class UpdateBackupRequest(proto.Message): accidentally by clients that do not know about them. """ - backup = proto.Field(proto.MESSAGE, number=1, message="Backup",) + backup = proto.Field( + proto.MESSAGE, + number=1, + message="Backup", + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -241,7 +448,10 @@ class GetBackupRequest(proto.Message): ``projects//instances//backups/``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class DeleteBackupRequest(proto.Message): @@ -255,7 +465,10 @@ class DeleteBackupRequest(proto.Message): ``projects//instances//backups/``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListBackupsRequest(proto.Message): @@ -325,10 +538,22 @@ class ListBackupsRequest(proto.Message): to the same ``parent`` and with the same ``filter``. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) class ListBackupsResponse(proto.Message): @@ -350,8 +575,15 @@ class ListBackupsResponse(proto.Message): def raw_page(self): return self - backups = proto.RepeatedField(proto.MESSAGE, number=1, message="Backup",) - next_page_token = proto.Field(proto.STRING, number=2,) + backups = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Backup", + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class ListBackupOperationsRequest(proto.Message): @@ -386,6 +618,8 @@ class ListBackupOperationsRequest(proto.Message): is ``type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata``. - ``metadata.`` - any field in metadata.value. + ``metadata.@type`` must be specified first if filtering + on metadata fields. - ``error`` - Error associated with the long-running operation. - ``response.@type`` - the type of response. @@ -399,8 +633,14 @@ class ListBackupOperationsRequest(proto.Message): Here are a few examples: - ``done:true`` - The operation is complete. - - ``metadata.database:prod`` - The database the backup was - taken from has a name containing the string "prod". + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` + ``metadata.database:prod`` - Returns operations where: + + - The operation's metadata type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + - The database the backup was taken from has a name + containing the string "prod". + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` ``(metadata.name:howl) AND`` ``(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND`` @@ -411,6 +651,37 @@ class ListBackupOperationsRequest(proto.Message): - The backup name contains the string "howl". - The operation started before 2018-03-28T14:50:00Z. - The operation resulted in an error. + + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND`` + ``(metadata.source_backup:test) AND`` + ``(metadata.progress.start_time < \"2022-01-18T14:50:00Z\") AND`` + ``(error:*)`` - Returns operations where: + + - The operation's metadata type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + - The source backup of the copied backup name contains + the string "test". + - The operation started before 2022-01-18T14:50:00Z. + - The operation resulted in an error. + + - ``((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` + ``(metadata.database:test_db)) OR`` + ``((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND`` + ``(metadata.source_backup:test_bkp)) AND`` + ``(error:*)`` - Returns operations where: + + - The operation's metadata matches either of criteria: + + - The operation's metadata type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata] + AND the database the backup was taken from has name + containing string "test_db" + - The operation's metadata type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata] + AND the backup the backup was copied from has name + containing string "test_bkp" + + - The operation resulted in an error. page_size (int): Number of operations to be returned in the response. If 0 or less, defaults to the server's @@ -423,10 +694,22 @@ class ListBackupOperationsRequest(proto.Message): to the same ``parent`` and with the same ``filter``. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) class ListBackupOperationsResponse(proto.Message): @@ -437,11 +720,9 @@ class ListBackupOperationsResponse(proto.Message): operations (Sequence[google.longrunning.operations_pb2.Operation]): The list of matching backup [long-running operations][google.longrunning.Operation]. Each operation's - name will be prefixed by the backup's name and the - operation's - [metadata][google.longrunning.Operation.metadata] will be of - type - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + name will be prefixed by the backup's name. The operation's + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. Operations returned include those that are pending or have completed/failed/canceled within the last 7 days. Operations returned are ordered by @@ -459,9 +740,14 @@ def raw_page(self): return self operations = proto.RepeatedField( - proto.MESSAGE, number=1, message=operations_pb2.Operation, + proto.MESSAGE, + number=1, + message=operations_pb2.Operation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class BackupInfo(proto.Message): @@ -487,12 +773,24 @@ class BackupInfo(proto.Message): from. """ - backup = proto.Field(proto.STRING, number=1,) + backup = proto.Field( + proto.STRING, + number=1, + ) version_time = proto.Field( - proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + create_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + source_database = proto.Field( + proto.STRING, + number=3, ) - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - source_database = proto.Field(proto.STRING, number=3,) class CreateBackupEncryptionConfig(proto.Message): @@ -516,8 +814,47 @@ class EncryptionType(proto.Enum): GOOGLE_DEFAULT_ENCRYPTION = 2 CUSTOMER_MANAGED_ENCRYPTION = 3 - encryption_type = proto.Field(proto.ENUM, number=1, enum=EncryptionType,) - kms_key_name = proto.Field(proto.STRING, number=2,) + encryption_type = proto.Field( + proto.ENUM, + number=1, + enum=EncryptionType, + ) + kms_key_name = proto.Field( + proto.STRING, + number=2, + ) + + +class CopyBackupEncryptionConfig(proto.Message): + r"""Encryption configuration for the copied backup. + + Attributes: + encryption_type (google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig.EncryptionType): + Required. The encryption type of the backup. + kms_key_name (str): + Optional. The Cloud KMS key that will be used to protect the + backup. This field should be set only when + [encryption_type][google.spanner.admin.database.v1.CopyBackupEncryptionConfig.encryption_type] + is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form + ``projects//locations//keyRings//cryptoKeys/``. + """ + + class EncryptionType(proto.Enum): + r"""Encryption types for the backup.""" + ENCRYPTION_TYPE_UNSPECIFIED = 0 + USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION = 1 + GOOGLE_DEFAULT_ENCRYPTION = 2 + CUSTOMER_MANAGED_ENCRYPTION = 3 + + encryption_type = proto.Field( + proto.ENUM, + number=1, + enum=EncryptionType, + ) + kms_key_name = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_admin_database_v1/types/common.py b/google/cloud/spanner_admin_database_v1/types/common.py index 81e3433617..6475e588bc 100644 --- a/google/cloud/spanner_admin_database_v1/types/common.py +++ b/google/cloud/spanner_admin_database_v1/types/common.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -52,9 +52,20 @@ class OperationProgress(proto.Message): failed or was completed successfully. """ - progress_percent = proto.Field(proto.INT32, number=1,) - start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + progress_percent = proto.Field( + proto.INT32, + number=1, + ) + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) class EncryptionConfig(proto.Message): @@ -67,7 +78,10 @@ class EncryptionConfig(proto.Message): ``projects//locations//keyRings//cryptoKeys/``. """ - kms_key_name = proto.Field(proto.STRING, number=2,) + kms_key_name = proto.Field( + proto.STRING, + number=2, + ) class EncryptionInfo(proto.Message): @@ -93,9 +107,20 @@ class Type(proto.Enum): GOOGLE_DEFAULT_ENCRYPTION = 1 CUSTOMER_MANAGED_ENCRYPTION = 2 - encryption_type = proto.Field(proto.ENUM, number=3, enum=Type,) - encryption_status = proto.Field(proto.MESSAGE, number=4, message=status_pb2.Status,) - kms_key_version = proto.Field(proto.STRING, number=2,) + encryption_type = proto.Field( + proto.ENUM, + number=3, + enum=Type, + ) + encryption_status = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + kms_key_version = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py b/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py index 7b598b09d9..52521db98d 100644 --- a/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +++ b/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -68,9 +68,16 @@ class RestoreInfo(proto.Message): This field is a member of `oneof`_ ``source_info``. """ - source_type = proto.Field(proto.ENUM, number=1, enum="RestoreSourceType",) + source_type = proto.Field( + proto.ENUM, + number=1, + enum="RestoreSourceType", + ) backup_info = proto.Field( - proto.MESSAGE, number=2, oneof="source_info", message=gsad_backup.BackupInfo, + proto.MESSAGE, + number=2, + oneof="source_info", + message=gsad_backup.BackupInfo, ) @@ -147,22 +154,53 @@ class State(proto.Enum): READY = 2 READY_OPTIMIZING = 3 - name = proto.Field(proto.STRING, number=1,) - state = proto.Field(proto.ENUM, number=2, enum=State,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - restore_info = proto.Field(proto.MESSAGE, number=4, message="RestoreInfo",) + name = proto.Field( + proto.STRING, + number=1, + ) + state = proto.Field( + proto.ENUM, + number=2, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + restore_info = proto.Field( + proto.MESSAGE, + number=4, + message="RestoreInfo", + ) encryption_config = proto.Field( - proto.MESSAGE, number=5, message=common.EncryptionConfig, + proto.MESSAGE, + number=5, + message=common.EncryptionConfig, ) encryption_info = proto.RepeatedField( - proto.MESSAGE, number=8, message=common.EncryptionInfo, + proto.MESSAGE, + number=8, + message=common.EncryptionInfo, + ) + version_retention_period = proto.Field( + proto.STRING, + number=6, ) - version_retention_period = proto.Field(proto.STRING, number=6,) earliest_version_time = proto.Field( - proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + default_leader = proto.Field( + proto.STRING, + number=9, + ) + database_dialect = proto.Field( + proto.ENUM, + number=10, + enum=common.DatabaseDialect, ) - default_leader = proto.Field(proto.STRING, number=9,) - database_dialect = proto.Field(proto.ENUM, number=10, enum=common.DatabaseDialect,) class ListDatabasesRequest(proto.Message): @@ -185,9 +223,18 @@ class ListDatabasesRequest(proto.Message): [ListDatabasesResponse][google.spanner.admin.database.v1.ListDatabasesResponse]. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) class ListDatabasesResponse(proto.Message): @@ -207,8 +254,15 @@ class ListDatabasesResponse(proto.Message): def raw_page(self): return self - databases = proto.RepeatedField(proto.MESSAGE, number=1, message="Database",) - next_page_token = proto.Field(proto.STRING, number=2,) + databases = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Database", + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class CreateDatabaseRequest(proto.Message): @@ -244,13 +298,28 @@ class CreateDatabaseRequest(proto.Message): Database. """ - parent = proto.Field(proto.STRING, number=1,) - create_statement = proto.Field(proto.STRING, number=2,) - extra_statements = proto.RepeatedField(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + create_statement = proto.Field( + proto.STRING, + number=2, + ) + extra_statements = proto.RepeatedField( + proto.STRING, + number=3, + ) encryption_config = proto.Field( - proto.MESSAGE, number=4, message=common.EncryptionConfig, + proto.MESSAGE, + number=4, + message=common.EncryptionConfig, + ) + database_dialect = proto.Field( + proto.ENUM, + number=5, + enum=common.DatabaseDialect, ) - database_dialect = proto.Field(proto.ENUM, number=5, enum=common.DatabaseDialect,) class CreateDatabaseMetadata(proto.Message): @@ -262,7 +331,10 @@ class CreateDatabaseMetadata(proto.Message): The database being created. """ - database = proto.Field(proto.STRING, number=1,) + database = proto.Field( + proto.STRING, + number=1, + ) class GetDatabaseRequest(proto.Message): @@ -276,7 +348,10 @@ class GetDatabaseRequest(proto.Message): ``projects//instances//databases/``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class UpdateDatabaseDdlRequest(proto.Message): @@ -327,9 +402,18 @@ class UpdateDatabaseDdlRequest(proto.Message): returns ``ALREADY_EXISTS``. """ - database = proto.Field(proto.STRING, number=1,) - statements = proto.RepeatedField(proto.STRING, number=2,) - operation_id = proto.Field(proto.STRING, number=3,) + database = proto.Field( + proto.STRING, + number=1, + ) + statements = proto.RepeatedField( + proto.STRING, + number=2, + ) + operation_id = proto.Field( + proto.STRING, + number=3, + ) class UpdateDatabaseDdlMetadata(proto.Message): @@ -365,14 +449,27 @@ class UpdateDatabaseDdlMetadata(proto.Message): ``statements[i]``. """ - database = proto.Field(proto.STRING, number=1,) - statements = proto.RepeatedField(proto.STRING, number=2,) + database = proto.Field( + proto.STRING, + number=1, + ) + statements = proto.RepeatedField( + proto.STRING, + number=2, + ) commit_timestamps = proto.RepeatedField( - proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + throttled = proto.Field( + proto.BOOL, + number=4, ) - throttled = proto.Field(proto.BOOL, number=4,) progress = proto.RepeatedField( - proto.MESSAGE, number=5, message=common.OperationProgress, + proto.MESSAGE, + number=5, + message=common.OperationProgress, ) @@ -385,7 +482,10 @@ class DropDatabaseRequest(proto.Message): Required. The database to be dropped. """ - database = proto.Field(proto.STRING, number=1,) + database = proto.Field( + proto.STRING, + number=1, + ) class GetDatabaseDdlRequest(proto.Message): @@ -399,7 +499,10 @@ class GetDatabaseDdlRequest(proto.Message): ``projects//instances//databases/`` """ - database = proto.Field(proto.STRING, number=1,) + database = proto.Field( + proto.STRING, + number=1, + ) class GetDatabaseDdlResponse(proto.Message): @@ -413,7 +516,10 @@ class GetDatabaseDdlResponse(proto.Message): request. """ - statements = proto.RepeatedField(proto.STRING, number=1,) + statements = proto.RepeatedField( + proto.STRING, + number=1, + ) class ListDatabaseOperationsRequest(proto.Message): @@ -447,6 +553,8 @@ class ListDatabaseOperationsRequest(proto.Message): is ``type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata``. - ``metadata.`` - any field in metadata.value. + ``metadata.@type`` must be specified first, if filtering + on metadata fields. - ``error`` - Error associated with the long-running operation. - ``response.@type`` - the type of response. @@ -486,10 +594,22 @@ class ListDatabaseOperationsRequest(proto.Message): to the same ``parent`` and with the same ``filter``. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) class ListDatabaseOperationsResponse(proto.Message): @@ -515,9 +635,14 @@ def raw_page(self): return self operations = proto.RepeatedField( - proto.MESSAGE, number=1, message=operations_pb2.Operation, + proto.MESSAGE, + number=1, + message=operations_pb2.Operation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class RestoreDatabaseRequest(proto.Message): @@ -556,11 +681,23 @@ class RestoreDatabaseRequest(proto.Message): = ``USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION``. """ - parent = proto.Field(proto.STRING, number=1,) - database_id = proto.Field(proto.STRING, number=2,) - backup = proto.Field(proto.STRING, number=3, oneof="source",) + parent = proto.Field( + proto.STRING, + number=1, + ) + database_id = proto.Field( + proto.STRING, + number=2, + ) + backup = proto.Field( + proto.STRING, + number=3, + oneof="source", + ) encryption_config = proto.Field( - proto.MESSAGE, number=4, message="RestoreDatabaseEncryptionConfig", + proto.MESSAGE, + number=4, + message="RestoreDatabaseEncryptionConfig", ) @@ -587,8 +724,15 @@ class EncryptionType(proto.Enum): GOOGLE_DEFAULT_ENCRYPTION = 2 CUSTOMER_MANAGED_ENCRYPTION = 3 - encryption_type = proto.Field(proto.ENUM, number=1, enum=EncryptionType,) - kms_key_name = proto.Field(proto.STRING, number=2,) + encryption_type = proto.Field( + proto.ENUM, + number=1, + enum=EncryptionType, + ) + kms_key_name = proto.Field( + proto.STRING, + number=2, + ) class RestoreDatabaseMetadata(proto.Message): @@ -644,14 +788,35 @@ class RestoreDatabaseMetadata(proto.Message): if the restore was not successful. """ - name = proto.Field(proto.STRING, number=1,) - source_type = proto.Field(proto.ENUM, number=2, enum="RestoreSourceType",) + name = proto.Field( + proto.STRING, + number=1, + ) + source_type = proto.Field( + proto.ENUM, + number=2, + enum="RestoreSourceType", + ) backup_info = proto.Field( - proto.MESSAGE, number=3, oneof="source_info", message=gsad_backup.BackupInfo, + proto.MESSAGE, + number=3, + oneof="source_info", + message=gsad_backup.BackupInfo, + ) + progress = proto.Field( + proto.MESSAGE, + number=4, + message=common.OperationProgress, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + optimize_database_operation_name = proto.Field( + proto.STRING, + number=6, ) - progress = proto.Field(proto.MESSAGE, number=4, message=common.OperationProgress,) - cancel_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - optimize_database_operation_name = proto.Field(proto.STRING, number=6,) class OptimizeRestoredDatabaseMetadata(proto.Message): @@ -670,8 +835,15 @@ class OptimizeRestoredDatabaseMetadata(proto.Message): optimizations. """ - name = proto.Field(proto.STRING, number=1,) - progress = proto.Field(proto.MESSAGE, number=2, message=common.OperationProgress,) + name = proto.Field( + proto.STRING, + number=1, + ) + progress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_admin_instance_v1/__init__.py b/google/cloud/spanner_admin_instance_v1/__init__.py index cdc373bcff..c641cd061c 100644 --- a/google/cloud/spanner_admin_instance_v1/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/services/__init__.py b/google/cloud/spanner_admin_instance_v1/services/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/google/cloud/spanner_admin_instance_v1/services/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py index 2ba47af654..15f143a119 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py index 35bbe7c817..4bbd9558c2 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -244,6 +244,26 @@ async def list_instance_configs( r"""Lists the supported instance configurations for a given project. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]): The request object. The request for @@ -313,12 +333,20 @@ async def list_instance_configs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListInstanceConfigsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -336,6 +364,25 @@ async def get_instance_config( r"""Gets information about a particular instance configuration. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_config(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]): The request object. The request for @@ -404,7 +451,12 @@ async def get_instance_config( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -420,6 +472,26 @@ async def list_instances( ) -> pagers.ListInstancesAsyncPager: r"""Lists all instances in the given project. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]): The request object. The request for @@ -489,12 +561,20 @@ async def list_instances( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListInstancesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -511,6 +591,25 @@ async def get_instance( ) -> spanner_instance_admin.Instance: r"""Gets information about a particular instance. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]): The request object. The request for @@ -577,7 +676,12 @@ async def get_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -632,6 +736,36 @@ async def create_instance( is [Instance][google.spanner.admin.instance.v1.Instance], if successful. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]): The request object. The request for @@ -711,7 +845,12 @@ async def create_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -780,6 +919,34 @@ async def update_instance( on resource [name][google.spanner.admin.instance.v1.Instance.name]. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]): The request object. The request for @@ -858,7 +1025,12 @@ async def update_instance( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -892,6 +1064,22 @@ async def delete_instance( irrevocably disappear from the API. All data in the databases is permanently deleted. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + client.delete_instance(request=request) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]): The request object. The request for @@ -953,7 +1141,10 @@ async def delete_instance( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def set_iam_policy( @@ -971,6 +1162,26 @@ async def set_iam_policy( Authorization requires ``spanner.instances.setIamPolicy`` on [resource][google.iam.v1.SetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` @@ -992,21 +1203,26 @@ async def set_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1021,17 +1237,17 @@ async def set_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1042,11 +1258,12 @@ async def set_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1064,7 +1281,9 @@ async def set_iam_policy( if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) elif not request: - request = iam_policy_pb2.SetIamPolicyRequest(resource=resource,) + request = iam_policy_pb2.SetIamPolicyRequest( + resource=resource, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1081,7 +1300,12 @@ async def set_iam_policy( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1102,6 +1326,26 @@ async def get_iam_policy( Authorization requires ``spanner.instances.getIamPolicy`` on [resource][google.iam.v1.GetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` @@ -1123,21 +1367,26 @@ async def get_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1152,17 +1401,17 @@ async def get_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1173,11 +1422,12 @@ async def get_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1195,7 +1445,9 @@ async def get_iam_policy( if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) elif not request: - request = iam_policy_pb2.GetIamPolicyRequest(resource=resource,) + request = iam_policy_pb2.GetIamPolicyRequest( + resource=resource, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1222,7 +1474,12 @@ async def get_iam_policy( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1245,6 +1502,27 @@ async def test_iam_permissions( ``spanner.instances.list`` permission on the containing Google Cloud Project. Otherwise returns an empty set of permissions. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for @@ -1293,7 +1571,8 @@ async def test_iam_permissions( request = iam_policy_pb2.TestIamPermissionsRequest(**request) elif not request: request = iam_policy_pb2.TestIamPermissionsRequest( - resource=resource, permissions=permissions, + resource=resource, + permissions=permissions, ) # Wrap the RPC method; this adds retry and timeout information, @@ -1311,7 +1590,12 @@ async def test_iam_permissions( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py index 66e1ebe8c2..9df92c95e6 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib @@ -58,7 +58,10 @@ class InstanceAdminClientMeta(type): _transport_registry["grpc"] = InstanceAdminGrpcTransport _transport_registry["grpc_asyncio"] = InstanceAdminGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[InstanceAdminTransport]: + def get_transport_class( + cls, + label: str = None, + ) -> Type[InstanceAdminTransport]: """Returns an appropriate transport class. Args: @@ -184,10 +187,14 @@ def transport(self) -> InstanceAdminTransport: return self._transport @staticmethod - def instance_path(project: str, instance: str,) -> str: + def instance_path( + project: str, + instance: str, + ) -> str: """Returns a fully-qualified instance string.""" return "projects/{project}/instances/{instance}".format( - project=project, instance=instance, + project=project, + instance=instance, ) @staticmethod @@ -197,10 +204,14 @@ def parse_instance_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def instance_config_path(project: str, instance_config: str,) -> str: + def instance_config_path( + project: str, + instance_config: str, + ) -> str: """Returns a fully-qualified instance_config string.""" return "projects/{project}/instanceConfigs/{instance_config}".format( - project=project, instance_config=instance_config, + project=project, + instance_config=instance_config, ) @staticmethod @@ -213,7 +224,9 @@ def parse_instance_config_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -226,9 +239,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -237,9 +254,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -248,9 +269,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -259,10 +284,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -448,6 +477,26 @@ def list_instance_configs( r"""Lists the supported instance configurations for a given project. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]): The request object. The request for @@ -507,12 +556,20 @@ def list_instance_configs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListInstanceConfigsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -530,6 +587,25 @@ def get_instance_config( r"""Gets information about a particular instance configuration. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_config(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]): The request object. The request for @@ -588,7 +664,12 @@ def get_instance_config( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -604,6 +685,26 @@ def list_instances( ) -> pagers.ListInstancesPager: r"""Lists all instances in the given project. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]): The request object. The request for @@ -663,12 +764,20 @@ def list_instances( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListInstancesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -685,6 +794,25 @@ def get_instance( ) -> spanner_instance_admin.Instance: r"""Gets information about a particular instance. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]): The request object. The request for @@ -741,7 +869,12 @@ def get_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -796,6 +929,36 @@ def create_instance( is [Instance][google.spanner.admin.instance.v1.Instance], if successful. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]): The request object. The request for @@ -875,7 +1038,12 @@ def create_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -944,6 +1112,34 @@ def update_instance( on resource [name][google.spanner.admin.instance.v1.Instance.name]. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]): The request object. The request for @@ -1022,7 +1218,12 @@ def update_instance( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1056,6 +1257,22 @@ def delete_instance( irrevocably disappear from the API. All data in the databases is permanently deleted. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + + def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + client.delete_instance(request=request) + Args: request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]): The request object. The request for @@ -1107,7 +1324,10 @@ def delete_instance( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def set_iam_policy( @@ -1125,6 +1345,26 @@ def set_iam_policy( Authorization requires ``spanner.instances.setIamPolicy`` on [resource][google.iam.v1.SetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): The request object. Request message for `SetIamPolicy` @@ -1146,21 +1386,26 @@ def set_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1175,17 +1420,17 @@ def set_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1196,11 +1441,12 @@ def set_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1234,7 +1480,12 @@ def set_iam_policy( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1255,6 +1506,26 @@ def get_iam_policy( Authorization requires ``spanner.instances.getIamPolicy`` on [resource][google.iam.v1.GetIamPolicyRequest.resource]. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): The request object. Request message for `GetIamPolicy` @@ -1276,21 +1547,26 @@ def get_iam_policy( Returns: google.iam.v1.policy_pb2.Policy: - Defines an Identity and Access Management (IAM) policy. It is used to - specify access control policies for Cloud Platform - resources. + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. A Policy is a collection of bindings. A binding binds - one or more members to a single role. Members can be - user accounts, service accounts, Google groups, and - domains (such as G Suite). A role is a named list of - permissions (defined by IAM or configured by users). - A binding can optionally specify a condition, which - is a logic expression that further constrains the - role binding based on attributes about the request - and/or target resource. - - **JSON Example** + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** { "bindings": [ @@ -1305,17 +1581,17 @@ def get_iam_policy( }, { "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], + "members": [ "user:eve@example.com" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } - ] + ], "etag": "BwWWja0YfJA=", "version": 3 } - **YAML Example** + **YAML example:** bindings: - members: - user:\ mike@example.com - group:\ admins@example.com - domain:google.com - @@ -1326,11 +1602,12 @@ def get_iam_policy( condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < - timestamp('2020-10-01T00:00:00.000Z') + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 For a description of IAM and its features, see the - [IAM developer's - guide](\ https://cloud.google.com/iam/docs). + [IAM + documentation](\ https://cloud.google.com/iam/docs/). """ # Create or coerce a protobuf request object. @@ -1364,7 +1641,12 @@ def get_iam_policy( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1387,6 +1669,27 @@ def test_iam_permissions( ``spanner.instances.list`` permission on the containing Google Cloud Project. Otherwise returns an empty set of permissions. + .. code-block:: python + + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): The request object. Request message for @@ -1452,7 +1755,12 @@ def test_iam_permissions( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py index 670978ab27..aec3583c56 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py index cdcf8eb941..30872fa32a 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py index f059f8eb67..bff88baf0c 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -88,6 +88,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -189,10 +190,14 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.create_instance: gapic_v1.method.wrap_method( - self.create_instance, default_timeout=3600.0, client_info=client_info, + self.create_instance, + default_timeout=3600.0, + client_info=client_info, ), self.update_instance: gapic_v1.method.wrap_method( - self.update_instance, default_timeout=3600.0, client_info=client_info, + self.update_instance, + default_timeout=3600.0, + client_info=client_info, ), self.delete_instance: gapic_v1.method.wrap_method( self.delete_instance, @@ -210,7 +215,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.set_iam_policy: gapic_v1.method.wrap_method( - self.set_iam_policy, default_timeout=30.0, client_info=client_info, + self.set_iam_policy, + default_timeout=30.0, + client_info=client_info, ), self.get_iam_policy: gapic_v1.method.wrap_method( self.get_iam_policy, @@ -237,9 +244,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -352,5 +359,9 @@ def test_iam_permissions( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("InstanceAdminTransport",) diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py index 366d6b9a88..1cb4b3d6ba 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -250,8 +250,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -657,5 +656,9 @@ def test_iam_permissions( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("InstanceAdminGrpcTransport",) diff --git a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py index 6ae38bdb42..830b947a8f 100644 --- a/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +++ b/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/types/__init__.py b/google/cloud/spanner_admin_instance_v1/types/__init__.py index 4833678c88..e403b6f3b6 100644 --- a/google/cloud/spanner_admin_instance_v1/types/__init__.py +++ b/google/cloud/spanner_admin_instance_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py b/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py index 51d4fbcc25..c4434b53b8 100644 --- a/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +++ b/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -67,9 +67,19 @@ class ReplicaType(proto.Enum): READ_ONLY = 2 WITNESS = 3 - location = proto.Field(proto.STRING, number=1,) - type_ = proto.Field(proto.ENUM, number=2, enum=ReplicaType,) - default_leader_location = proto.Field(proto.BOOL, number=3,) + location = proto.Field( + proto.STRING, + number=1, + ) + type_ = proto.Field( + proto.ENUM, + number=2, + enum=ReplicaType, + ) + default_leader_location = proto.Field( + proto.BOOL, + number=3, + ) class InstanceConfig(proto.Message): @@ -94,10 +104,23 @@ class InstanceConfig(proto.Message): databases in instances that use this instance configuration. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - replicas = proto.RepeatedField(proto.MESSAGE, number=3, message="ReplicaInfo",) - leader_options = proto.RepeatedField(proto.STRING, number=4,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + replicas = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ReplicaInfo", + ) + leader_options = proto.RepeatedField( + proto.STRING, + number=4, + ) class Instance(proto.Message): @@ -144,7 +167,7 @@ class Instance(proto.Message): the state must be either omitted or set to ``CREATING``. For [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance], the state must be either omitted or set to ``READY``. - labels (Sequence[google.cloud.spanner_admin_instance_v1.types.Instance.LabelsEntry]): + labels (Mapping[str, str]): Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources into groups that reflect a customer's organizational needs and deployment strategies. @@ -183,14 +206,40 @@ class State(proto.Enum): CREATING = 1 READY = 2 - name = proto.Field(proto.STRING, number=1,) - config = proto.Field(proto.STRING, number=2,) - display_name = proto.Field(proto.STRING, number=3,) - node_count = proto.Field(proto.INT32, number=5,) - processing_units = proto.Field(proto.INT32, number=9,) - state = proto.Field(proto.ENUM, number=6, enum=State,) - labels = proto.MapField(proto.STRING, proto.STRING, number=7,) - endpoint_uris = proto.RepeatedField(proto.STRING, number=8,) + name = proto.Field( + proto.STRING, + number=1, + ) + config = proto.Field( + proto.STRING, + number=2, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + node_count = proto.Field( + proto.INT32, + number=5, + ) + processing_units = proto.Field( + proto.INT32, + number=9, + ) + state = proto.Field( + proto.ENUM, + number=6, + enum=State, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=7, + ) + endpoint_uris = proto.RepeatedField( + proto.STRING, + number=8, + ) class ListInstanceConfigsRequest(proto.Message): @@ -213,9 +262,18 @@ class ListInstanceConfigsRequest(proto.Message): [ListInstanceConfigsResponse][google.spanner.admin.instance.v1.ListInstanceConfigsResponse]. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) class ListInstanceConfigsResponse(proto.Message): @@ -237,9 +295,14 @@ def raw_page(self): return self instance_configs = proto.RepeatedField( - proto.MESSAGE, number=1, message="InstanceConfig", + proto.MESSAGE, + number=1, + message="InstanceConfig", + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class GetInstanceConfigRequest(proto.Message): @@ -253,7 +316,10 @@ class GetInstanceConfigRequest(proto.Message): ``projects//instanceConfigs/``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class GetInstanceRequest(proto.Message): @@ -272,8 +338,15 @@ class GetInstanceRequest(proto.Message): are returned. """ - name = proto.Field(proto.STRING, number=1,) - field_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + name = proto.Field( + proto.STRING, + number=1, + ) + field_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) class CreateInstanceRequest(proto.Message): @@ -294,9 +367,19 @@ class CreateInstanceRequest(proto.Message): ``/instances/``. """ - parent = proto.Field(proto.STRING, number=1,) - instance_id = proto.Field(proto.STRING, number=2,) - instance = proto.Field(proto.MESSAGE, number=3, message="Instance",) + parent = proto.Field( + proto.STRING, + number=1, + ) + instance_id = proto.Field( + proto.STRING, + number=2, + ) + instance = proto.Field( + proto.MESSAGE, + number=3, + message="Instance", + ) class ListInstancesRequest(proto.Message): @@ -341,10 +424,22 @@ class ListInstancesRequest(proto.Message): containing "dev". """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class ListInstancesResponse(proto.Message): @@ -364,8 +459,15 @@ class ListInstancesResponse(proto.Message): def raw_page(self): return self - instances = proto.RepeatedField(proto.MESSAGE, number=1, message="Instance",) - next_page_token = proto.Field(proto.STRING, number=2,) + instances = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Instance", + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateInstanceRequest(proto.Message): @@ -388,8 +490,16 @@ class UpdateInstanceRequest(proto.Message): them. """ - instance = proto.Field(proto.MESSAGE, number=1, message="Instance",) - field_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + instance = proto.Field( + proto.MESSAGE, + number=1, + message="Instance", + ) + field_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) class DeleteInstanceRequest(proto.Message): @@ -402,7 +512,10 @@ class DeleteInstanceRequest(proto.Message): of the form ``projects//instances/`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateInstanceMetadata(proto.Message): @@ -426,10 +539,26 @@ class CreateInstanceMetadata(proto.Message): was completed successfully. """ - instance = proto.Field(proto.MESSAGE, number=1, message="Instance",) - start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - cancel_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + instance = proto.Field( + proto.MESSAGE, + number=1, + message="Instance", + ) + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) class UpdateInstanceMetadata(proto.Message): @@ -453,10 +582,26 @@ class UpdateInstanceMetadata(proto.Message): was completed successfully. """ - instance = proto.Field(proto.MESSAGE, number=1, message="Instance",) - start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - cancel_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + instance = proto.Field( + proto.MESSAGE, + number=1, + message="Instance", + ) + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + cancel_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_dbapi/connection.py b/google/cloud/spanner_dbapi/connection.py index 0da0c15584..76f04338c4 100644 --- a/google/cloud/spanner_dbapi/connection.py +++ b/google/cloud/spanner_dbapi/connection.py @@ -446,7 +446,8 @@ def run_statement(self, statement, retried=False): ) else: _execute_insert_heterogenous( - transaction, parts.get("sql_params_list"), + transaction, + parts.get("sql_params_list"), ) return ( iter(()), @@ -455,7 +456,9 @@ def run_statement(self, statement, retried=False): return ( transaction.execute_sql( - statement.sql, statement.params, param_types=statement.param_types, + statement.sql, + statement.params, + param_types=statement.param_types, ), ResultsChecksum() if retried else statement.checksum, ) diff --git a/google/cloud/spanner_dbapi/cursor.py b/google/cloud/spanner_dbapi/cursor.py index 7c8c5bdbc5..0fc36a72a9 100644 --- a/google/cloud/spanner_dbapi/cursor.py +++ b/google/cloud/spanner_dbapi/cursor.py @@ -260,9 +260,10 @@ def execute(self, sql, args=None): class_ == parse_utils.STMT_INSERT, ) - (self._result_set, self._checksum,) = self.connection.run_statement( - statement - ) + ( + self._result_set, + self._checksum, + ) = self.connection.run_statement(statement) while True: try: self._itr = PeekIterator(self._result_set) diff --git a/google/cloud/spanner_v1/backup.py b/google/cloud/spanner_v1/backup.py index dba7ba1fcb..a7b7a972b6 100644 --- a/google/cloud/spanner_v1/backup.py +++ b/google/cloud/spanner_v1/backup.py @@ -21,6 +21,8 @@ from google.cloud.spanner_admin_database_v1 import Backup as BackupPB from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig from google.cloud.spanner_admin_database_v1 import CreateBackupRequest +from google.cloud.spanner_admin_database_v1 import CopyBackupEncryptionConfig +from google.cloud.spanner_admin_database_v1 import CopyBackupRequest from google.cloud.spanner_v1._helpers import _metadata_with_prefix _BACKUP_NAME_RE = re.compile( @@ -77,10 +79,12 @@ def __init__( expire_time=None, version_time=None, encryption_config=None, + source_backup=None, ): self.backup_id = backup_id self._instance = instance self._database = database + self._source_backup = source_backup self._expire_time = expire_time self._create_time = None self._version_time = version_time @@ -88,8 +92,17 @@ def __init__( self._state = None self._referencing_databases = None self._encryption_info = None + self._max_expire_time = None + self._referencing_backups = None if type(encryption_config) == dict: - self._encryption_config = CreateBackupEncryptionConfig(**encryption_config) + if source_backup: + self._encryption_config = CopyBackupEncryptionConfig( + **encryption_config + ) + else: + self._encryption_config = CreateBackupEncryptionConfig( + **encryption_config + ) else: self._encryption_config = encryption_config @@ -185,6 +198,24 @@ def encryption_info(self): """ return self._encryption_info + @property + def max_expire_time(self): + """The max allowed expiration time of the backup. + :rtype: :class:`datetime.datetime` + :returns: a datetime object representing the max expire time of + this backup + """ + return self._max_expire_time + + @property + def referencing_backups(self): + """The names of the destination backups being created by copying this source backup. + :rtype: list of strings + :returns: a list of backup path strings which specify the backups that are + referencing this copy backup + """ + return self._referencing_backups + @classmethod def from_pb(cls, backup_pb, instance): """Create an instance of this class from a protobuf message. @@ -223,7 +254,7 @@ def from_pb(cls, backup_pb, instance): return cls(backup_id, instance) def create(self): - """Create this backup within its instance. + """Create this backup or backup copy within its instance. :rtype: :class:`~google.api_core.operation.Operation` :returns: a future used to poll the status of the create request @@ -234,17 +265,42 @@ def create(self): """ if not self._expire_time: raise ValueError("expire_time not set") - if not self._database: - raise ValueError("database not set") + + if not self._database and not self._source_backup: + raise ValueError("database and source backup both not set") + if ( - self._encryption_config + ( + self._encryption_config + and self._encryption_config.kms_key_name + and self._encryption_config.encryption_type + != CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION + ) + and self._encryption_config and self._encryption_config.kms_key_name and self._encryption_config.encryption_type - != CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION + != CopyBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION ): raise ValueError("kms_key_name only used with CUSTOMER_MANAGED_ENCRYPTION") + api = self._instance._client.database_admin_api metadata = _metadata_with_prefix(self.name) + + if self._source_backup: + request = CopyBackupRequest( + parent=self._instance.name, + backup_id=self.backup_id, + source_backup=self._source_backup, + expire_time=self._expire_time, + encryption_config=self._encryption_config, + ) + + future = api.copy_backup( + request=request, + metadata=metadata, + ) + return future + backup = BackupPB( database=self._database, expire_time=self.expire_time, @@ -258,7 +314,10 @@ def create(self): encryption_config=self._encryption_config, ) - future = api.create_backup(request=request, metadata=metadata,) + future = api.create_backup( + request=request, + metadata=metadata, + ) return future def exists(self): @@ -294,6 +353,8 @@ def reload(self): self._state = BackupPB.State(pb.state) self._referencing_databases = pb.referencing_databases self._encryption_info = pb.encryption_info + self._max_expire_time = pb.max_expire_time + self._referencing_backups = pb.referencing_backups def update_expire_time(self, new_expire_time): """Update the expire time of this backup. @@ -303,7 +364,10 @@ def update_expire_time(self, new_expire_time): """ api = self._instance._client.database_admin_api metadata = _metadata_with_prefix(self.name) - backup_update = BackupPB(name=self.name, expire_time=new_expire_time,) + backup_update = BackupPB( + name=self.name, + expire_time=new_expire_time, + ) update_mask = {"paths": ["expire_time"]} api.update_backup( backup=backup_update, update_mask=update_mask, metadata=metadata diff --git a/google/cloud/spanner_v1/batch.py b/google/cloud/spanner_v1/batch.py index 4d8364df1f..48c533d2cd 100644 --- a/google/cloud/spanner_v1/batch.py +++ b/google/cloud/spanner_v1/batch.py @@ -179,7 +179,10 @@ def commit(self, return_commit_stats=False, request_options=None): request_options=request_options, ) with trace_call("CloudSpanner.Commit", self._session, trace_attributes): - response = api.commit(request=request, metadata=metadata,) + response = api.commit( + request=request, + metadata=metadata, + ) self.committed = response.commit_timestamp self.commit_stats = response.commit_stats return self.committed diff --git a/google/cloud/spanner_v1/database.py b/google/cloud/spanner_v1/database.py index 7ccefc1228..90916bc710 100644 --- a/google/cloud/spanner_v1/database.py +++ b/google/cloud/spanner_v1/database.py @@ -441,7 +441,9 @@ def update_ddl(self, ddl_statements, operation_id=""): metadata = _metadata_with_prefix(self.name) request = UpdateDatabaseDdlRequest( - database=self.name, statements=ddl_statements, operation_id=operation_id, + database=self.name, + statements=ddl_statements, + operation_id=operation_id, ) future = api.update_database_ddl(request=request, metadata=metadata) @@ -544,7 +546,8 @@ def execute_pdml(): request_options=request_options, ) method = functools.partial( - api.execute_streaming_sql, metadata=metadata, + api.execute_streaming_sql, + metadata=metadata, ) iterator = _restart_on_unavailable(method, request) @@ -694,7 +697,10 @@ def restore(self, source): backup=source.name, encryption_config=self._encryption_config or None, ) - future = api.restore_database(request=request, metadata=metadata,) + future = api.restore_database( + request=request, + metadata=metadata, + ) return future def is_ready(self): @@ -862,6 +868,12 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): """End ``with`` block.""" + if isinstance(exc_val, NotFound): + # If NotFound exception occurs inside the with block + # then we validate if the session still exists. + if not self._session.exists(): + self._session = self._database._pool._new_session() + self._session.create() self._database._pool.put(self._session) @@ -1032,7 +1044,11 @@ def generate_read_batches( yield {"partition": partition, "read": read_info.copy()} def process_read_batch( - self, batch, *, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, + self, + batch, + *, + retry=gapic_v1.method.DEFAULT, + timeout=gapic_v1.method.DEFAULT, ): """Process a single, partitioned read. @@ -1149,7 +1165,11 @@ def generate_query_batches( yield {"partition": partition, "query": query_info} def process_query_batch( - self, batch, *, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, + self, + batch, + *, + retry=gapic_v1.method.DEFAULT, + timeout=gapic_v1.method.DEFAULT, ): """Process a single, partitioned query. diff --git a/google/cloud/spanner_v1/instance.py b/google/cloud/spanner_v1/instance.py index 75e70eaf17..f8869d1f7b 100644 --- a/google/cloud/spanner_v1/instance.py +++ b/google/cloud/spanner_v1/instance.py @@ -44,6 +44,7 @@ _OPERATION_METADATA_MESSAGES = ( backup.Backup, backup.CreateBackupMetadata, + backup.CopyBackupMetadata, spanner_database_admin.CreateDatabaseMetadata, spanner_database_admin.Database, spanner_database_admin.OptimizeRestoredDatabaseMetadata, @@ -58,6 +59,7 @@ _OPERATION_RESPONSE_TYPES = { backup.CreateBackupMetadata: backup.Backup, + backup.CopyBackupMetadata: backup.Backup, spanner_database_admin.CreateDatabaseMetadata: spanner_database_admin.Database, spanner_database_admin.OptimizeRestoredDatabaseMetadata: spanner_database_admin.Database, spanner_database_admin.RestoreDatabaseMetadata: spanner_database_admin.Database, @@ -551,6 +553,41 @@ def backup( encryption_config=encryption_config, ) + def copy_backup( + self, + backup_id, + source_backup, + expire_time=None, + encryption_config=None, + ): + """Factory to create a copy backup within this instance. + + :type backup_id: str + :param backup_id: The ID of the backup copy. + :type source_backup: str + :param source_backup_id: The full path of the source backup to be copied. + :type expire_time: :class:`datetime.datetime` + :param expire_time: + Optional. The expire time that will be used when creating the copy backup. + Required if the create method needs to be called. + :type encryption_config: + :class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig` + or :class:`dict` + :param encryption_config: + (Optional) Encryption configuration for the backup. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig` + :rtype: :class:`~google.cloud.spanner_v1.backup.Backup` + :returns: a copy backup owned by this instance. + """ + return Backup( + backup_id, + self, + source_backup=source_backup, + expire_time=expire_time, + encryption_config=encryption_config, + ) + def list_backups(self, filter_="", page_size=None): """List backups for the instance. @@ -571,7 +608,9 @@ def list_backups(self, filter_="", page_size=None): """ metadata = _metadata_with_prefix(self.name) request = ListBackupsRequest( - parent=self.name, filter=filter_, page_size=page_size, + parent=self.name, + filter=filter_, + page_size=page_size, ) page_iter = self._client.database_admin_api.list_backups( request=request, metadata=metadata @@ -599,7 +638,9 @@ def list_backup_operations(self, filter_="", page_size=None): """ metadata = _metadata_with_prefix(self.name) request = ListBackupOperationsRequest( - parent=self.name, filter=filter_, page_size=page_size, + parent=self.name, + filter=filter_, + page_size=page_size, ) page_iter = self._client.database_admin_api.list_backup_operations( request=request, metadata=metadata @@ -627,7 +668,9 @@ def list_database_operations(self, filter_="", page_size=None): """ metadata = _metadata_with_prefix(self.name) request = ListDatabaseOperationsRequest( - parent=self.name, filter=filter_, page_size=page_size, + parent=self.name, + filter=filter_, + page_size=page_size, ) page_iter = self._client.database_admin_api.list_database_operations( request=request, metadata=metadata diff --git a/google/cloud/spanner_v1/services/__init__.py b/google/cloud/spanner_v1/services/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/google/cloud/spanner_v1/services/__init__.py +++ b/google/cloud/spanner_v1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_v1/services/spanner/__init__.py b/google/cloud/spanner_v1/services/spanner/__init__.py index 53f14ea629..106bb31c15 100644 --- a/google/cloud/spanner_v1/services/spanner/__init__.py +++ b/google/cloud/spanner_v1/services/spanner/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_v1/services/spanner/async_client.py b/google/cloud/spanner_v1/services/spanner/async_client.py index cc01d8d659..e831c1c9b4 100644 --- a/google/cloud/spanner_v1/services/spanner/async_client.py +++ b/google/cloud/spanner_v1/services/spanner/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import re from typing import ( Dict, + Mapping, Optional, AsyncIterable, Awaitable, @@ -244,6 +245,25 @@ async def create_session( Idle sessions can be kept alive by sending a trivial SQL query periodically, e.g., ``"SELECT 1"``. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_create_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = client.create_session(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]): The request object. The request for @@ -306,7 +326,12 @@ async def create_session( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -326,6 +351,26 @@ async def batch_create_sessions( the clients. See https://goo.gl/TgSFN2 for best practices on session cache management. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = client.batch_create_sessions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]): The request object. The request for @@ -404,7 +449,12 @@ async def batch_create_sessions( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -422,6 +472,25 @@ async def get_session( exist. This is mainly useful for determining whether a session is still alive. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_get_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = client.get_session(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]): The request object. The request for @@ -484,7 +553,12 @@ async def get_session( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -500,6 +574,26 @@ async def list_sessions( ) -> pagers.ListSessionsAsyncPager: r"""Lists all sessions in a given database. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]): The request object. The request for @@ -567,12 +661,20 @@ async def list_sessions( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListSessionsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -591,6 +693,22 @@ async def delete_session( with it. This will asynchronously trigger cancellation of any operations that are running with this session. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + client.delete_session(request=request) + Args: request (Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]): The request object. The request for @@ -650,7 +768,10 @@ async def delete_session( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def execute_sql( @@ -676,6 +797,26 @@ async def execute_sql( [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.execute_sql(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): The request object. The request for @@ -720,7 +861,12 @@ async def execute_sql( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -740,6 +886,27 @@ def execute_streaming_sql( individual row in the result set can exceed 100 MiB, and no column value can exceed 10 MiB. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = client.execute_streaming_sql(request=request) + + # Handle the response + for response in stream: + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): The request object. The request for @@ -778,7 +945,12 @@ def execute_streaming_sql( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -806,6 +978,30 @@ async def execute_batch_dml( Execution stops after the first failed statement; the remaining statements are not executed. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = client.execute_batch_dml(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]): The request object. The request for @@ -886,7 +1082,12 @@ async def execute_batch_dml( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -915,6 +1116,27 @@ async def read( calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + response = client.read(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): The request object. The request for @@ -959,7 +1181,12 @@ async def read( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -979,6 +1206,28 @@ def streaming_read( the result set can exceed 100 MiB, and no column value can exceed 10 MiB. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + stream = client.streaming_read(request=request) + + # Handle the response + for response in stream: + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): The request object. The request for @@ -1017,7 +1266,12 @@ def streaming_read( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1038,6 +1292,25 @@ async def begin_transaction( [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a side-effect. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = client.begin_transaction(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]): The request object. The request for @@ -1109,7 +1382,12 @@ async def begin_transaction( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1143,6 +1421,26 @@ async def commit( perform another read from the database to see the state of things as they are now. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_commit(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = client.commit(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.CommitRequest, dict]): The request object. The request for @@ -1246,7 +1544,12 @@ async def commit( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1272,6 +1575,23 @@ async def rollback( transaction is not found. ``Rollback`` never returns ``ABORTED``. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_rollback(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + client.rollback(request=request) + Args: request (Union[google.cloud.spanner_v1.types.RollbackRequest, dict]): The request object. The request for @@ -1340,7 +1660,10 @@ async def rollback( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def partition_query( @@ -1366,6 +1689,26 @@ async def partition_query( to resume the query, and the whole operation must be restarted from the beginning. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.partition_query(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]): The request object. The request for @@ -1410,7 +1753,12 @@ async def partition_query( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1441,6 +1789,26 @@ async def partition_read( to resume the read, and the whole operation must be restarted from the beginning. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = client.partition_read(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]): The request object. The request for @@ -1485,7 +1853,12 @@ async def partition_read( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1499,7 +1872,9 @@ async def __aexit__(self, exc_type, exc, tb): try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-spanner",).version, + gapic_version=pkg_resources.get_distribution( + "google-cloud-spanner", + ).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() diff --git a/google/cloud/spanner_v1/services/spanner/client.py b/google/cloud/spanner_v1/services/spanner/client.py index b701d16d29..a9203fb6a3 100644 --- a/google/cloud/spanner_v1/services/spanner/client.py +++ b/google/cloud/spanner_v1/services/spanner/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ from collections import OrderedDict import os import re -from typing import Dict, Optional, Iterable, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Iterable, Sequence, Tuple, Type, Union import pkg_resources from google.api_core import client_options as client_options_lib @@ -60,7 +60,10 @@ class SpannerClientMeta(type): _transport_registry["grpc"] = SpannerGrpcTransport _transport_registry["grpc_asyncio"] = SpannerGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[SpannerTransport]: + def get_transport_class( + cls, + label: str = None, + ) -> Type[SpannerTransport]: """Returns an appropriate transport class. Args: @@ -168,10 +171,16 @@ def transport(self) -> SpannerTransport: return self._transport @staticmethod - def database_path(project: str, instance: str, database: str,) -> str: + def database_path( + project: str, + instance: str, + database: str, + ) -> str: """Returns a fully-qualified database string.""" return "projects/{project}/instances/{instance}/databases/{database}".format( - project=project, instance=instance, database=database, + project=project, + instance=instance, + database=database, ) @staticmethod @@ -184,10 +193,18 @@ def parse_database_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def session_path(project: str, instance: str, database: str, session: str,) -> str: + def session_path( + project: str, + instance: str, + database: str, + session: str, + ) -> str: """Returns a fully-qualified session string.""" return "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}".format( - project=project, instance=instance, database=database, session=session, + project=project, + instance=instance, + database=database, + session=session, ) @staticmethod @@ -200,7 +217,9 @@ def parse_session_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, @@ -213,9 +232,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str,) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder,) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -224,9 +247,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str,) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization,) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -235,9 +262,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str,) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project,) + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -246,10 +277,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -452,6 +487,25 @@ def create_session( Idle sessions can be kept alive by sending a trivial SQL query periodically, e.g., ``"SELECT 1"``. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_create_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = client.create_session(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]): The request object. The request for @@ -505,7 +559,12 @@ def create_session( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -525,6 +584,26 @@ def batch_create_sessions( the clients. See https://goo.gl/TgSFN2 for best practices on session cache management. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = client.batch_create_sessions(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]): The request object. The request for @@ -594,7 +673,12 @@ def batch_create_sessions( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -612,6 +696,25 @@ def get_session( exist. This is mainly useful for determining whether a session is still alive. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_get_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = client.get_session(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]): The request object. The request for @@ -665,7 +768,12 @@ def get_session( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -681,6 +789,26 @@ def list_sessions( ) -> pagers.ListSessionsPager: r"""Lists all sessions in a given database. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]): The request object. The request for @@ -739,12 +867,20 @@ def list_sessions( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListSessionsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -763,6 +899,22 @@ def delete_session( with it. This will asynchronously trigger cancellation of any operations that are running with this session. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + client.delete_session(request=request) + Args: request (Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]): The request object. The request for @@ -813,7 +965,10 @@ def delete_session( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def execute_sql( @@ -839,6 +994,26 @@ def execute_sql( [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.execute_sql(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): The request object. The request for @@ -875,7 +1050,12 @@ def execute_sql( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -895,6 +1075,27 @@ def execute_streaming_sql( individual row in the result set can exceed 100 MiB, and no column value can exceed 10 MiB. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = client.execute_streaming_sql(request=request) + + # Handle the response + for response in stream: + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): The request object. The request for @@ -934,7 +1135,12 @@ def execute_streaming_sql( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -962,6 +1168,30 @@ def execute_batch_dml( Execution stops after the first failed statement; the remaining statements are not executed. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = client.execute_batch_dml(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]): The request object. The request for @@ -1034,7 +1264,12 @@ def execute_batch_dml( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1063,6 +1298,27 @@ def read( calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + response = client.read(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): The request object. The request for @@ -1099,7 +1355,12 @@ def read( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1119,6 +1380,28 @@ def streaming_read( the result set can exceed 100 MiB, and no column value can exceed 10 MiB. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + stream = client.streaming_read(request=request) + + # Handle the response + for response in stream: + print(response) + Args: request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): The request object. The request for @@ -1158,7 +1441,12 @@ def streaming_read( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1179,6 +1467,25 @@ def begin_transaction( [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a side-effect. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = client.begin_transaction(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]): The request object. The request for @@ -1241,7 +1548,12 @@ def begin_transaction( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1275,6 +1587,26 @@ def commit( perform another read from the database to see the state of things as they are now. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_commit(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = client.commit(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.CommitRequest, dict]): The request object. The request for @@ -1369,7 +1701,12 @@ def commit( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1395,6 +1732,23 @@ def rollback( transaction is not found. ``Rollback`` never returns ``ABORTED``. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_rollback(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + client.rollback(request=request) + Args: request (Union[google.cloud.spanner_v1.types.RollbackRequest, dict]): The request object. The request for @@ -1454,7 +1808,10 @@ def rollback( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def partition_query( @@ -1480,6 +1837,26 @@ def partition_query( to resume the query, and the whole operation must be restarted from the beginning. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.partition_query(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]): The request object. The request for @@ -1516,7 +1893,12 @@ def partition_query( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1547,6 +1929,26 @@ def partition_read( to resume the read, and the whole operation must be restarted from the beginning. + .. code-block:: python + + from google.cloud import spanner_v1 + + def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = client.partition_read(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]): The request object. The request for @@ -1583,7 +1985,12 @@ def partition_read( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response @@ -1604,7 +2011,9 @@ def __exit__(self, type, value, traceback): try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-spanner",).version, + gapic_version=pkg_resources.get_distribution( + "google-cloud-spanner", + ).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() diff --git a/google/cloud/spanner_v1/services/spanner/pagers.py b/google/cloud/spanner_v1/services/spanner/pagers.py index 8b73b00fda..ff83dc50d5 100644 --- a/google/cloud/spanner_v1/services/spanner/pagers.py +++ b/google/cloud/spanner_v1/services/spanner/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_v1/services/spanner/transports/__init__.py b/google/cloud/spanner_v1/services/spanner/transports/__init__.py index 189d62b427..ac786d2f15 100644 --- a/google/cloud/spanner_v1/services/spanner/transports/__init__.py +++ b/google/cloud/spanner_v1/services/spanner/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_v1/services/spanner/transports/base.py b/google/cloud/spanner_v1/services/spanner/transports/base.py index f3d946b51d..608c894a9a 100644 --- a/google/cloud/spanner_v1/services/spanner/transports/base.py +++ b/google/cloud/spanner_v1/services/spanner/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,7 +33,9 @@ try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=pkg_resources.get_distribution("google-cloud-spanner",).version, + gapic_version=pkg_resources.get_distribution( + "google-cloud-spanner", + ).version, ) except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() @@ -85,6 +87,7 @@ def __init__( always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" @@ -243,7 +246,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.streaming_read: gapic_v1.method.wrap_method( - self.streaming_read, default_timeout=3600.0, client_info=client_info, + self.streaming_read, + default_timeout=3600.0, + client_info=client_info, ), self.begin_transaction: gapic_v1.method.wrap_method( self.begin_transaction, @@ -320,9 +325,9 @@ def _prep_wrapped_messages(self, client_info): def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @@ -466,5 +471,9 @@ def partition_read( ]: raise NotImplementedError() + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("SpannerTransport",) diff --git a/google/cloud/spanner_v1/services/spanner/transports/grpc.py b/google/cloud/spanner_v1/services/spanner/transports/grpc.py index f5cdfc3fec..86a3ca9967 100644 --- a/google/cloud/spanner_v1/services/spanner/transports/grpc.py +++ b/google/cloud/spanner_v1/services/spanner/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -230,8 +230,7 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -755,5 +754,9 @@ def partition_read( def close(self): self.grpc_channel.close() + @property + def kind(self) -> str: + return "grpc" + __all__ = ("SpannerGrpcTransport",) diff --git a/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py b/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py index 14e086d313..95d58bc06a 100644 --- a/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +++ b/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/spanner_v1/session.py b/google/cloud/spanner_v1/session.py index 5eca0a8d2f..1ab6a93626 100644 --- a/google/cloud/spanner_v1/session.py +++ b/google/cloud/spanner_v1/session.py @@ -120,7 +120,10 @@ def create(self): request.session.labels = self._labels with trace_call("CloudSpanner.CreateSession", self, self._labels): - session_pb = api.create_session(request=request, metadata=metadata,) + session_pb = api.create_session( + request=request, + metadata=metadata, + ) self._session_id = session_pb.name.split("/")[-1] def exists(self): @@ -438,4 +441,4 @@ def _get_retry_delay(cause, attempts): nanos = retry_info.retry_delay.nanos return retry_info.retry_delay.seconds + nanos / 1.0e9 - return 2 ** attempts + random.random() + return 2**attempts + random.random() diff --git a/google/cloud/spanner_v1/snapshot.py b/google/cloud/spanner_v1/snapshot.py index aaf9caa2fc..75aed33e33 100644 --- a/google/cloud/spanner_v1/snapshot.py +++ b/google/cloud/spanner_v1/snapshot.py @@ -449,7 +449,10 @@ def partition_read( "CloudSpanner.PartitionReadOnlyTransaction", self._session, trace_attributes ): response = api.partition_read( - request=request, metadata=metadata, retry=retry, timeout=timeout, + request=request, + metadata=metadata, + retry=retry, + timeout=timeout, ) return [partition.partition_token for partition in response.partitions] @@ -541,7 +544,10 @@ def partition_query( trace_attributes, ): response = api.partition_query( - request=request, metadata=metadata, retry=retry, timeout=timeout, + request=request, + metadata=metadata, + retry=retry, + timeout=timeout, ) return [partition.partition_token for partition in response.partitions] diff --git a/google/cloud/spanner_v1/streamed.py b/google/cloud/spanner_v1/streamed.py index 3b7eb7c89a..80a452d558 100644 --- a/google/cloud/spanner_v1/streamed.py +++ b/google/cloud/spanner_v1/streamed.py @@ -205,7 +205,11 @@ class Unmergeable(ValueError): """ def __init__(self, lhs, rhs, type_): - message = "Cannot merge %s values: %s %s" % (TypeCode(type_.code), lhs, rhs,) + message = "Cannot merge %s values: %s %s" % ( + TypeCode(type_.code), + lhs, + rhs, + ) super(Unmergeable, self).__init__(message) diff --git a/google/cloud/spanner_v1/transaction.py b/google/cloud/spanner_v1/transaction.py index b960761147..d776b12469 100644 --- a/google/cloud/spanner_v1/transaction.py +++ b/google/cloud/spanner_v1/transaction.py @@ -166,7 +166,10 @@ def commit(self, return_commit_stats=False, request_options=None): request_options=request_options, ) with trace_call("CloudSpanner.Commit", self._session, trace_attributes): - response = api.commit(request=request, metadata=metadata,) + response = api.commit( + request=request, + metadata=metadata, + ) self.committed = response.commit_timestamp if return_commit_stats: self.commit_stats = response.commit_stats diff --git a/google/cloud/spanner_v1/types/__init__.py b/google/cloud/spanner_v1/types/__init__.py index 01dde4208a..c8d97aa910 100644 --- a/google/cloud/spanner_v1/types/__init__.py +++ b/google/cloud/spanner_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,12 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .commit_response import CommitResponse +from .commit_response import ( + CommitResponse, +) from .keys import ( KeyRange, KeySet, ) -from .mutation import Mutation +from .mutation import ( + Mutation, +) from .query_plan import ( PlanNode, QueryPlan, diff --git a/google/cloud/spanner_v1/types/commit_response.py b/google/cloud/spanner_v1/types/commit_response.py index e9a289f0ce..837cbbf4f4 100644 --- a/google/cloud/spanner_v1/types/commit_response.py +++ b/google/cloud/spanner_v1/types/commit_response.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,12 @@ from google.protobuf import timestamp_pb2 # type: ignore -__protobuf__ = proto.module(package="google.spanner.v1", manifest={"CommitResponse",},) +__protobuf__ = proto.module( + package="google.spanner.v1", + manifest={ + "CommitResponse", + }, +) class CommitResponse(proto.Message): @@ -50,12 +55,21 @@ class CommitStats(proto.Message): `INVALID_ARGUMENT `__. """ - mutation_count = proto.Field(proto.INT64, number=1,) + mutation_count = proto.Field( + proto.INT64, + number=1, + ) commit_timestamp = proto.Field( - proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + commit_stats = proto.Field( + proto.MESSAGE, + number=2, + message=CommitStats, ) - commit_stats = proto.Field(proto.MESSAGE, number=2, message=CommitStats,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_v1/types/keys.py b/google/cloud/spanner_v1/types/keys.py index d0ec1e92b7..81e6e1360c 100644 --- a/google/cloud/spanner_v1/types/keys.py +++ b/google/cloud/spanner_v1/types/keys.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,11 @@ __protobuf__ = proto.module( - package="google.spanner.v1", manifest={"KeyRange", "KeySet",}, + package="google.spanner.v1", + manifest={ + "KeyRange", + "KeySet", + }, ) @@ -169,16 +173,28 @@ class KeyRange(proto.Message): """ start_closed = proto.Field( - proto.MESSAGE, number=1, oneof="start_key_type", message=struct_pb2.ListValue, + proto.MESSAGE, + number=1, + oneof="start_key_type", + message=struct_pb2.ListValue, ) start_open = proto.Field( - proto.MESSAGE, number=2, oneof="start_key_type", message=struct_pb2.ListValue, + proto.MESSAGE, + number=2, + oneof="start_key_type", + message=struct_pb2.ListValue, ) end_closed = proto.Field( - proto.MESSAGE, number=3, oneof="end_key_type", message=struct_pb2.ListValue, + proto.MESSAGE, + number=3, + oneof="end_key_type", + message=struct_pb2.ListValue, ) end_open = proto.Field( - proto.MESSAGE, number=4, oneof="end_key_type", message=struct_pb2.ListValue, + proto.MESSAGE, + number=4, + oneof="end_key_type", + message=struct_pb2.ListValue, ) @@ -209,9 +225,20 @@ class KeySet(proto.Message): only yielded once. """ - keys = proto.RepeatedField(proto.MESSAGE, number=1, message=struct_pb2.ListValue,) - ranges = proto.RepeatedField(proto.MESSAGE, number=2, message="KeyRange",) - all_ = proto.Field(proto.BOOL, number=3,) + keys = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=struct_pb2.ListValue, + ) + ranges = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="KeyRange", + ) + all_ = proto.Field( + proto.BOOL, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_v1/types/mutation.py b/google/cloud/spanner_v1/types/mutation.py index 5cbd660c0f..2ad2db30ac 100644 --- a/google/cloud/spanner_v1/types/mutation.py +++ b/google/cloud/spanner_v1/types/mutation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,12 @@ from google.protobuf import struct_pb2 # type: ignore -__protobuf__ = proto.module(package="google.spanner.v1", manifest={"Mutation",},) +__protobuf__ = proto.module( + package="google.spanner.v1", + manifest={ + "Mutation", + }, +) class Mutation(proto.Message): @@ -116,10 +121,18 @@ class Write(proto.Message): [here][google.spanner.v1.TypeCode]. """ - table = proto.Field(proto.STRING, number=1,) - columns = proto.RepeatedField(proto.STRING, number=2,) + table = proto.Field( + proto.STRING, + number=1, + ) + columns = proto.RepeatedField( + proto.STRING, + number=2, + ) values = proto.RepeatedField( - proto.MESSAGE, number=3, message=struct_pb2.ListValue, + proto.MESSAGE, + number=3, + message=struct_pb2.ListValue, ) class Delete(proto.Message): @@ -139,16 +152,46 @@ class Delete(proto.Message): succeed even if some or all rows do not exist. """ - table = proto.Field(proto.STRING, number=1,) - key_set = proto.Field(proto.MESSAGE, number=2, message=keys.KeySet,) + table = proto.Field( + proto.STRING, + number=1, + ) + key_set = proto.Field( + proto.MESSAGE, + number=2, + message=keys.KeySet, + ) - insert = proto.Field(proto.MESSAGE, number=1, oneof="operation", message=Write,) - update = proto.Field(proto.MESSAGE, number=2, oneof="operation", message=Write,) + insert = proto.Field( + proto.MESSAGE, + number=1, + oneof="operation", + message=Write, + ) + update = proto.Field( + proto.MESSAGE, + number=2, + oneof="operation", + message=Write, + ) insert_or_update = proto.Field( - proto.MESSAGE, number=3, oneof="operation", message=Write, + proto.MESSAGE, + number=3, + oneof="operation", + message=Write, + ) + replace = proto.Field( + proto.MESSAGE, + number=4, + oneof="operation", + message=Write, + ) + delete = proto.Field( + proto.MESSAGE, + number=5, + oneof="operation", + message=Delete, ) - replace = proto.Field(proto.MESSAGE, number=4, oneof="operation", message=Write,) - delete = proto.Field(proto.MESSAGE, number=5, oneof="operation", message=Delete,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_v1/types/query_plan.py b/google/cloud/spanner_v1/types/query_plan.py index 27df7bc908..465e9972be 100644 --- a/google/cloud/spanner_v1/types/query_plan.py +++ b/google/cloud/spanner_v1/types/query_plan.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,11 @@ __protobuf__ = proto.module( - package="google.spanner.v1", manifest={"PlanNode", "QueryPlan",}, + package="google.spanner.v1", + manifest={ + "PlanNode", + "QueryPlan", + }, ) @@ -101,9 +105,18 @@ class ChildLink(proto.Message): to the variable names assigned to the columns. """ - child_index = proto.Field(proto.INT32, number=1,) - type_ = proto.Field(proto.STRING, number=2,) - variable = proto.Field(proto.STRING, number=3,) + child_index = proto.Field( + proto.INT32, + number=1, + ) + type_ = proto.Field( + proto.STRING, + number=2, + ) + variable = proto.Field( + proto.STRING, + number=3, + ) class ShortRepresentation(proto.Message): r"""Condensed representation of a node and its subtree. Only present for @@ -113,7 +126,7 @@ class ShortRepresentation(proto.Message): description (str): A string representation of the expression subtree rooted at this node. - subqueries (Sequence[google.cloud.spanner_v1.types.PlanNode.ShortRepresentation.SubqueriesEntry]): + subqueries (Mapping[str, int]): A mapping of (subquery variable name) -> (subquery node id) for cases where the ``description`` string of this node references a ``SCALAR`` subquery contained in the expression @@ -121,18 +134,49 @@ class ShortRepresentation(proto.Message): subquery may not necessarily be a direct child of this node. """ - description = proto.Field(proto.STRING, number=1,) - subqueries = proto.MapField(proto.STRING, proto.INT32, number=2,) - - index = proto.Field(proto.INT32, number=1,) - kind = proto.Field(proto.ENUM, number=2, enum=Kind,) - display_name = proto.Field(proto.STRING, number=3,) - child_links = proto.RepeatedField(proto.MESSAGE, number=4, message=ChildLink,) + description = proto.Field( + proto.STRING, + number=1, + ) + subqueries = proto.MapField( + proto.STRING, + proto.INT32, + number=2, + ) + + index = proto.Field( + proto.INT32, + number=1, + ) + kind = proto.Field( + proto.ENUM, + number=2, + enum=Kind, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + child_links = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=ChildLink, + ) short_representation = proto.Field( - proto.MESSAGE, number=5, message=ShortRepresentation, + proto.MESSAGE, + number=5, + message=ShortRepresentation, + ) + metadata = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Struct, + ) + execution_stats = proto.Field( + proto.MESSAGE, + number=7, + message=struct_pb2.Struct, ) - metadata = proto.Field(proto.MESSAGE, number=6, message=struct_pb2.Struct,) - execution_stats = proto.Field(proto.MESSAGE, number=7, message=struct_pb2.Struct,) class QueryPlan(proto.Message): @@ -147,7 +191,11 @@ class QueryPlan(proto.Message): to its index in ``plan_nodes``. """ - plan_nodes = proto.RepeatedField(proto.MESSAGE, number=1, message="PlanNode",) + plan_nodes = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="PlanNode", + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_v1/types/result_set.py b/google/cloud/spanner_v1/types/result_set.py index bd5d5ebfbb..68ff3700c5 100644 --- a/google/cloud/spanner_v1/types/result_set.py +++ b/google/cloud/spanner_v1/types/result_set.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,7 +23,12 @@ __protobuf__ = proto.module( package="google.spanner.v1", - manifest={"ResultSet", "PartialResultSet", "ResultSetMetadata", "ResultSetStats",}, + manifest={ + "ResultSet", + "PartialResultSet", + "ResultSetMetadata", + "ResultSetStats", + }, ) @@ -55,9 +60,21 @@ class ResultSet(proto.Message): [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. """ - metadata = proto.Field(proto.MESSAGE, number=1, message="ResultSetMetadata",) - rows = proto.RepeatedField(proto.MESSAGE, number=2, message=struct_pb2.ListValue,) - stats = proto.Field(proto.MESSAGE, number=3, message="ResultSetStats",) + metadata = proto.Field( + proto.MESSAGE, + number=1, + message="ResultSetMetadata", + ) + rows = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.ListValue, + ) + stats = proto.Field( + proto.MESSAGE, + number=3, + message="ResultSetStats", + ) class PartialResultSet(proto.Message): @@ -175,11 +192,29 @@ class PartialResultSet(proto.Message): statements. """ - metadata = proto.Field(proto.MESSAGE, number=1, message="ResultSetMetadata",) - values = proto.RepeatedField(proto.MESSAGE, number=2, message=struct_pb2.Value,) - chunked_value = proto.Field(proto.BOOL, number=3,) - resume_token = proto.Field(proto.BYTES, number=4,) - stats = proto.Field(proto.MESSAGE, number=5, message="ResultSetStats",) + metadata = proto.Field( + proto.MESSAGE, + number=1, + message="ResultSetMetadata", + ) + values = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + chunked_value = proto.Field( + proto.BOOL, + number=3, + ) + resume_token = proto.Field( + proto.BYTES, + number=4, + ) + stats = proto.Field( + proto.MESSAGE, + number=5, + message="ResultSetStats", + ) class ResultSetMetadata(proto.Message): @@ -205,9 +240,15 @@ class ResultSetMetadata(proto.Message): transaction is yielded here. """ - row_type = proto.Field(proto.MESSAGE, number=1, message=gs_type.StructType,) + row_type = proto.Field( + proto.MESSAGE, + number=1, + message=gs_type.StructType, + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.Transaction, + proto.MESSAGE, + number=2, + message=gs_transaction.Transaction, ) @@ -252,10 +293,26 @@ class ResultSetStats(proto.Message): This field is a member of `oneof`_ ``row_count``. """ - query_plan = proto.Field(proto.MESSAGE, number=1, message=gs_query_plan.QueryPlan,) - query_stats = proto.Field(proto.MESSAGE, number=2, message=struct_pb2.Struct,) - row_count_exact = proto.Field(proto.INT64, number=3, oneof="row_count",) - row_count_lower_bound = proto.Field(proto.INT64, number=4, oneof="row_count",) + query_plan = proto.Field( + proto.MESSAGE, + number=1, + message=gs_query_plan.QueryPlan, + ) + query_stats = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) + row_count_exact = proto.Field( + proto.INT64, + number=3, + oneof="row_count", + ) + row_count_lower_bound = proto.Field( + proto.INT64, + number=4, + oneof="row_count", + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_v1/types/spanner.py b/google/cloud/spanner_v1/types/spanner.py index 2bdde094eb..f6cacdc323 100644 --- a/google/cloud/spanner_v1/types/spanner.py +++ b/google/cloud/spanner_v1/types/spanner.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -62,11 +62,18 @@ class CreateSessionRequest(proto.Message): Required. The database in which the new session is created. session (google.cloud.spanner_v1.types.Session): - The session to create. + Required. The session to create. """ - database = proto.Field(proto.STRING, number=1,) - session = proto.Field(proto.MESSAGE, number=2, message="Session",) + database = proto.Field( + proto.STRING, + number=1, + ) + session = proto.Field( + proto.MESSAGE, + number=2, + message="Session", + ) class BatchCreateSessionsRequest(proto.Message): @@ -90,9 +97,19 @@ class BatchCreateSessionsRequest(proto.Message): as necessary). """ - database = proto.Field(proto.STRING, number=1,) - session_template = proto.Field(proto.MESSAGE, number=2, message="Session",) - session_count = proto.Field(proto.INT32, number=3,) + database = proto.Field( + proto.STRING, + number=1, + ) + session_template = proto.Field( + proto.MESSAGE, + number=2, + message="Session", + ) + session_count = proto.Field( + proto.INT32, + number=3, + ) class BatchCreateSessionsResponse(proto.Message): @@ -104,7 +121,11 @@ class BatchCreateSessionsResponse(proto.Message): The freshly created sessions. """ - session = proto.RepeatedField(proto.MESSAGE, number=1, message="Session",) + session = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Session", + ) class Session(proto.Message): @@ -114,7 +135,7 @@ class Session(proto.Message): name (str): Output only. The name of the session. This is always system-assigned. - labels (Sequence[google.cloud.spanner_v1.types.Session.LabelsEntry]): + labels (Mapping[str, str]): The labels for the session. - Label keys must be between 1 and 63 characters long and @@ -137,11 +158,24 @@ class Session(proto.Message): earlier than the actual last use time. """ - name = proto.Field(proto.STRING, number=1,) - labels = proto.MapField(proto.STRING, proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) approximate_last_use_time = proto.Field( - proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, ) @@ -154,7 +188,10 @@ class GetSessionRequest(proto.Message): retrieve. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListSessionsRequest(proto.Message): @@ -188,10 +225,22 @@ class ListSessionsRequest(proto.Message): and the value of the label contains the string "dev". """ - database = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + database = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class ListSessionsResponse(proto.Message): @@ -211,8 +260,15 @@ class ListSessionsResponse(proto.Message): def raw_page(self): return self - sessions = proto.RepeatedField(proto.MESSAGE, number=1, message="Session",) - next_page_token = proto.Field(proto.STRING, number=2,) + sessions = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Session", + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class DeleteSessionRequest(proto.Message): @@ -224,7 +280,10 @@ class DeleteSessionRequest(proto.Message): Required. The name of the session to delete. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class RequestOptions(proto.Message): @@ -282,9 +341,19 @@ class Priority(proto.Enum): PRIORITY_MEDIUM = 2 PRIORITY_HIGH = 3 - priority = proto.Field(proto.ENUM, number=1, enum=Priority,) - request_tag = proto.Field(proto.STRING, number=2,) - transaction_tag = proto.Field(proto.STRING, number=3,) + priority = proto.Field( + proto.ENUM, + number=1, + enum=Priority, + ) + request_tag = proto.Field( + proto.STRING, + number=2, + ) + transaction_tag = proto.Field( + proto.STRING, + number=3, + ) class ExecuteSqlRequest(proto.Message): @@ -329,7 +398,7 @@ class ExecuteSqlRequest(proto.Message): It is an error to execute a SQL statement with unbound parameters. - param_types (Sequence[google.cloud.spanner_v1.types.ExecuteSqlRequest.ParamTypesEntry]): + param_types (Mapping[str, google.cloud.spanner_v1.types.Type]): It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type ``BYTES`` and values of type ``STRING`` both appear in @@ -450,24 +519,66 @@ class QueryOptions(proto.Message): garbage collection fails with an ``INVALID_ARGUMENT`` error. """ - optimizer_version = proto.Field(proto.STRING, number=1,) - optimizer_statistics_package = proto.Field(proto.STRING, number=2,) + optimizer_version = proto.Field( + proto.STRING, + number=1, + ) + optimizer_statistics_package = proto.Field( + proto.STRING, + number=2, + ) - session = proto.Field(proto.STRING, number=1,) + session = proto.Field( + proto.STRING, + number=1, + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.TransactionSelector, + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + sql = proto.Field( + proto.STRING, + number=3, + ) + params = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Struct, ) - sql = proto.Field(proto.STRING, number=3,) - params = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Struct,) param_types = proto.MapField( - proto.STRING, proto.MESSAGE, number=5, message=gs_type.Type, + proto.STRING, + proto.MESSAGE, + number=5, + message=gs_type.Type, + ) + resume_token = proto.Field( + proto.BYTES, + number=6, + ) + query_mode = proto.Field( + proto.ENUM, + number=7, + enum=QueryMode, + ) + partition_token = proto.Field( + proto.BYTES, + number=8, + ) + seqno = proto.Field( + proto.INT64, + number=9, + ) + query_options = proto.Field( + proto.MESSAGE, + number=10, + message=QueryOptions, + ) + request_options = proto.Field( + proto.MESSAGE, + number=11, + message="RequestOptions", ) - resume_token = proto.Field(proto.BYTES, number=6,) - query_mode = proto.Field(proto.ENUM, number=7, enum=QueryMode,) - partition_token = proto.Field(proto.BYTES, number=8,) - seqno = proto.Field(proto.INT64, number=9,) - query_options = proto.Field(proto.MESSAGE, number=10, message=QueryOptions,) - request_options = proto.Field(proto.MESSAGE, number=11, message="RequestOptions",) class ExecuteBatchDmlRequest(proto.Message): @@ -534,7 +645,7 @@ class Statement(proto.Message): It is an error to execute a SQL statement with unbound parameters. - param_types (Sequence[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest.Statement.ParamTypesEntry]): + param_types (Mapping[str, google.cloud.spanner_v1.types.Type]): It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type ``BYTES`` and values of type ``STRING`` both appear in @@ -548,19 +659,45 @@ class Statement(proto.Message): SQL types. """ - sql = proto.Field(proto.STRING, number=1,) - params = proto.Field(proto.MESSAGE, number=2, message=struct_pb2.Struct,) + sql = proto.Field( + proto.STRING, + number=1, + ) + params = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) param_types = proto.MapField( - proto.STRING, proto.MESSAGE, number=3, message=gs_type.Type, + proto.STRING, + proto.MESSAGE, + number=3, + message=gs_type.Type, ) - session = proto.Field(proto.STRING, number=1,) + session = proto.Field( + proto.STRING, + number=1, + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.TransactionSelector, + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + statements = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Statement, + ) + seqno = proto.Field( + proto.INT64, + number=4, + ) + request_options = proto.Field( + proto.MESSAGE, + number=5, + message="RequestOptions", ) - statements = proto.RepeatedField(proto.MESSAGE, number=3, message=Statement,) - seqno = proto.Field(proto.INT64, number=4,) - request_options = proto.Field(proto.MESSAGE, number=5, message="RequestOptions",) class ExecuteBatchDmlResponse(proto.Message): @@ -619,9 +756,15 @@ class ExecuteBatchDmlResponse(proto.Message): """ result_sets = proto.RepeatedField( - proto.MESSAGE, number=1, message=result_set.ResultSet, + proto.MESSAGE, + number=1, + message=result_set.ResultSet, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, ) - status = proto.Field(proto.MESSAGE, number=2, message=status_pb2.Status,) class PartitionOptions(proto.Message): @@ -649,8 +792,14 @@ class PartitionOptions(proto.Message): this maximum count request. """ - partition_size_bytes = proto.Field(proto.INT64, number=1,) - max_partitions = proto.Field(proto.INT64, number=2,) + partition_size_bytes = proto.Field( + proto.INT64, + number=1, + ) + max_partitions = proto.Field( + proto.INT64, + number=2, + ) class PartitionQueryRequest(proto.Message): @@ -696,7 +845,7 @@ class PartitionQueryRequest(proto.Message): It is an error to execute a SQL statement with unbound parameters. - param_types (Sequence[google.cloud.spanner_v1.types.PartitionQueryRequest.ParamTypesEntry]): + param_types (Mapping[str, google.cloud.spanner_v1.types.Type]): It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type ``BYTES`` and values of type ``STRING`` both appear in @@ -712,17 +861,34 @@ class PartitionQueryRequest(proto.Message): partitions are created. """ - session = proto.Field(proto.STRING, number=1,) + session = proto.Field( + proto.STRING, + number=1, + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.TransactionSelector, + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + sql = proto.Field( + proto.STRING, + number=3, + ) + params = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Struct, ) - sql = proto.Field(proto.STRING, number=3,) - params = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Struct,) param_types = proto.MapField( - proto.STRING, proto.MESSAGE, number=5, message=gs_type.Type, + proto.STRING, + proto.MESSAGE, + number=5, + message=gs_type.Type, ) partition_options = proto.Field( - proto.MESSAGE, number=6, message="PartitionOptions", + proto.MESSAGE, + number=6, + message="PartitionOptions", ) @@ -775,16 +941,36 @@ class PartitionReadRequest(proto.Message): partitions are created. """ - session = proto.Field(proto.STRING, number=1,) + session = proto.Field( + proto.STRING, + number=1, + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.TransactionSelector, + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + table = proto.Field( + proto.STRING, + number=3, + ) + index = proto.Field( + proto.STRING, + number=4, + ) + columns = proto.RepeatedField( + proto.STRING, + number=5, + ) + key_set = proto.Field( + proto.MESSAGE, + number=6, + message=keys.KeySet, ) - table = proto.Field(proto.STRING, number=3,) - index = proto.Field(proto.STRING, number=4,) - columns = proto.RepeatedField(proto.STRING, number=5,) - key_set = proto.Field(proto.MESSAGE, number=6, message=keys.KeySet,) partition_options = proto.Field( - proto.MESSAGE, number=9, message="PartitionOptions", + proto.MESSAGE, + number=9, + message="PartitionOptions", ) @@ -801,7 +987,10 @@ class Partition(proto.Message): token. """ - partition_token = proto.Field(proto.BYTES, number=1,) + partition_token = proto.Field( + proto.BYTES, + number=1, + ) class PartitionResponse(proto.Message): @@ -816,9 +1005,15 @@ class PartitionResponse(proto.Message): Transaction created by this request. """ - partitions = proto.RepeatedField(proto.MESSAGE, number=1, message="Partition",) + partitions = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Partition", + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.Transaction, + proto.MESSAGE, + number=2, + message=gs_transaction.Transaction, ) @@ -896,18 +1091,49 @@ class ReadRequest(proto.Message): Common options for this request. """ - session = proto.Field(proto.STRING, number=1,) + session = proto.Field( + proto.STRING, + number=1, + ) transaction = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.TransactionSelector, + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + table = proto.Field( + proto.STRING, + number=3, + ) + index = proto.Field( + proto.STRING, + number=4, + ) + columns = proto.RepeatedField( + proto.STRING, + number=5, + ) + key_set = proto.Field( + proto.MESSAGE, + number=6, + message=keys.KeySet, + ) + limit = proto.Field( + proto.INT64, + number=8, + ) + resume_token = proto.Field( + proto.BYTES, + number=9, + ) + partition_token = proto.Field( + proto.BYTES, + number=10, + ) + request_options = proto.Field( + proto.MESSAGE, + number=11, + message="RequestOptions", ) - table = proto.Field(proto.STRING, number=3,) - index = proto.Field(proto.STRING, number=4,) - columns = proto.RepeatedField(proto.STRING, number=5,) - key_set = proto.Field(proto.MESSAGE, number=6, message=keys.KeySet,) - limit = proto.Field(proto.INT64, number=8,) - resume_token = proto.Field(proto.BYTES, number=9,) - partition_token = proto.Field(proto.BYTES, number=10,) - request_options = proto.Field(proto.MESSAGE, number=11, message="RequestOptions",) class BeginTransactionRequest(proto.Message): @@ -928,11 +1154,20 @@ class BeginTransactionRequest(proto.Message): this transaction instead. """ - session = proto.Field(proto.STRING, number=1,) + session = proto.Field( + proto.STRING, + number=1, + ) options = proto.Field( - proto.MESSAGE, number=2, message=gs_transaction.TransactionOptions, + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionOptions, + ) + request_options = proto.Field( + proto.MESSAGE, + number=3, + message="RequestOptions", ) - request_options = proto.Field(proto.MESSAGE, number=3, message="RequestOptions",) class CommitRequest(proto.Message): @@ -979,17 +1214,35 @@ class CommitRequest(proto.Message): Common options for this request. """ - session = proto.Field(proto.STRING, number=1,) - transaction_id = proto.Field(proto.BYTES, number=2, oneof="transaction",) + session = proto.Field( + proto.STRING, + number=1, + ) + transaction_id = proto.Field( + proto.BYTES, + number=2, + oneof="transaction", + ) single_use_transaction = proto.Field( proto.MESSAGE, number=3, oneof="transaction", message=gs_transaction.TransactionOptions, ) - mutations = proto.RepeatedField(proto.MESSAGE, number=4, message=mutation.Mutation,) - return_commit_stats = proto.Field(proto.BOOL, number=5,) - request_options = proto.Field(proto.MESSAGE, number=6, message="RequestOptions",) + mutations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=mutation.Mutation, + ) + return_commit_stats = proto.Field( + proto.BOOL, + number=5, + ) + request_options = proto.Field( + proto.MESSAGE, + number=6, + message="RequestOptions", + ) class RollbackRequest(proto.Message): @@ -1003,8 +1256,14 @@ class RollbackRequest(proto.Message): Required. The transaction to roll back. """ - session = proto.Field(proto.STRING, number=1,) - transaction_id = proto.Field(proto.BYTES, number=2,) + session = proto.Field( + proto.STRING, + number=1, + ) + transaction_id = proto.Field( + proto.BYTES, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/spanner_v1/types/transaction.py b/google/cloud/spanner_v1/types/transaction.py index 04b8552a48..7c0a766c58 100644 --- a/google/cloud/spanner_v1/types/transaction.py +++ b/google/cloud/spanner_v1/types/transaction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,11 @@ __protobuf__ = proto.module( package="google.spanner.v1", - manifest={"TransactionOptions", "Transaction", "TransactionSelector",}, + manifest={ + "TransactionOptions", + "Transaction", + "TransactionSelector", + }, ) @@ -340,8 +344,7 @@ class ReadWrite(proto.Message): """ class PartitionedDml(proto.Message): - r"""Message type to initiate a Partitioned DML transaction. - """ + r"""Message type to initiate a Partitioned DML transaction.""" class ReadOnly(proto.Message): r"""Message type to initiate a read-only transaction. @@ -427,7 +430,11 @@ class ReadOnly(proto.Message): message that describes the transaction. """ - strong = proto.Field(proto.BOOL, number=1, oneof="timestamp_bound",) + strong = proto.Field( + proto.BOOL, + number=1, + oneof="timestamp_bound", + ) min_read_timestamp = proto.Field( proto.MESSAGE, number=2, @@ -452,13 +459,29 @@ class ReadOnly(proto.Message): oneof="timestamp_bound", message=duration_pb2.Duration, ) - return_read_timestamp = proto.Field(proto.BOOL, number=6,) + return_read_timestamp = proto.Field( + proto.BOOL, + number=6, + ) - read_write = proto.Field(proto.MESSAGE, number=1, oneof="mode", message=ReadWrite,) + read_write = proto.Field( + proto.MESSAGE, + number=1, + oneof="mode", + message=ReadWrite, + ) partitioned_dml = proto.Field( - proto.MESSAGE, number=3, oneof="mode", message=PartitionedDml, + proto.MESSAGE, + number=3, + oneof="mode", + message=PartitionedDml, + ) + read_only = proto.Field( + proto.MESSAGE, + number=2, + oneof="mode", + message=ReadOnly, ) - read_only = proto.Field(proto.MESSAGE, number=2, oneof="mode", message=ReadOnly,) class Transaction(proto.Message): @@ -483,9 +506,14 @@ class Transaction(proto.Message): nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. """ - id = proto.Field(proto.BYTES, number=1,) + id = proto.Field( + proto.BYTES, + number=1, + ) read_timestamp = proto.Field( - proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, ) @@ -528,11 +556,21 @@ class TransactionSelector(proto.Message): """ single_use = proto.Field( - proto.MESSAGE, number=1, oneof="selector", message="TransactionOptions", + proto.MESSAGE, + number=1, + oneof="selector", + message="TransactionOptions", + ) + id = proto.Field( + proto.BYTES, + number=2, + oneof="selector", ) - id = proto.Field(proto.BYTES, number=2, oneof="selector",) begin = proto.Field( - proto.MESSAGE, number=3, oneof="selector", message="TransactionOptions", + proto.MESSAGE, + number=3, + oneof="selector", + message="TransactionOptions", ) diff --git a/google/cloud/spanner_v1/types/type.py b/google/cloud/spanner_v1/types/type.py index 5673fcb77d..12b06fc737 100644 --- a/google/cloud/spanner_v1/types/type.py +++ b/google/cloud/spanner_v1/types/type.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,12 @@ __protobuf__ = proto.module( package="google.spanner.v1", - manifest={"TypeCode", "TypeAnnotationCode", "Type", "StructType",}, + manifest={ + "TypeCode", + "TypeAnnotationCode", + "Type", + "StructType", + }, ) @@ -88,10 +93,26 @@ class Type(proto.Message): on the read path. """ - code = proto.Field(proto.ENUM, number=1, enum="TypeCode",) - array_element_type = proto.Field(proto.MESSAGE, number=2, message="Type",) - struct_type = proto.Field(proto.MESSAGE, number=3, message="StructType",) - type_annotation = proto.Field(proto.ENUM, number=4, enum="TypeAnnotationCode",) + code = proto.Field( + proto.ENUM, + number=1, + enum="TypeCode", + ) + array_element_type = proto.Field( + proto.MESSAGE, + number=2, + message="Type", + ) + struct_type = proto.Field( + proto.MESSAGE, + number=3, + message="StructType", + ) + type_annotation = proto.Field( + proto.ENUM, + number=4, + enum="TypeAnnotationCode", + ) class StructType(proto.Message): @@ -126,10 +147,21 @@ class Field(proto.Message): The type of the field. """ - name = proto.Field(proto.STRING, number=1,) - type_ = proto.Field(proto.MESSAGE, number=2, message="Type",) - - fields = proto.RepeatedField(proto.MESSAGE, number=1, message=Field,) + name = proto.Field( + proto.STRING, + number=1, + ) + type_ = proto.Field( + proto.MESSAGE, + number=2, + message="Type", + ) + + fields = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=Field, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/noxfile.py b/noxfile.py index 7759904126..efe3b70104 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,16 +20,42 @@ import os import pathlib import shutil +import warnings import nox - -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" -SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] + UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] +UNIT_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", +] +UNIT_TEST_EXTERNAL_DEPENDENCIES = [] +UNIT_TEST_LOCAL_DEPENDENCIES = [] +UNIT_TEST_DEPENDENCIES = [] +UNIT_TEST_EXTRAS = [] +UNIT_TEST_EXTRAS_BY_PYTHON = {} + +SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "pytest", + "google-cloud-testutils", +] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES = [] +SYSTEM_TEST_DEPENDENCIES = [] +SYSTEM_TEST_EXTRAS = [ + "tracing", +] +SYSTEM_TEST_EXTRAS_BY_PYTHON = {} CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() @@ -57,7 +83,9 @@ def lint(session): """ session.install("flake8", BLACK_VERSION) session.run( - "black", "--check", *BLACK_PATHS, + "black", + "--check", + *BLACK_PATHS, ) session.run("flake8", "google", "tests") @@ -67,7 +95,8 @@ def blacken(session): """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( - "black", *BLACK_PATHS, + "black", + *BLACK_PATHS, ) @@ -78,23 +107,41 @@ def lint_setup_py(session): session.run("python", "setup.py", "check", "--restructuredtext", "--strict") +def install_unittest_dependencies(session, *constraints): + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, *constraints) + + if UNIT_TEST_EXTERNAL_DEPENDENCIES: + warnings.warn( + "'unit_test_external_dependencies' is deprecated. Instead, please " + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", + DeprecationWarning, + ) + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_LOCAL_DEPENDENCIES: + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_EXTRAS_BY_PYTHON: + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif UNIT_TEST_EXTRAS: + extras = UNIT_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + def default(session): # Install all test dependencies, then install this package in-place. constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - session.install( - "mock", - "asyncmock", - "pytest", - "pytest-cov", - "pytest-asyncio", - "-c", - constraints_path, - ) - - session.install("-e", ".", "-c", constraints_path) + install_unittest_dependencies(session, "-c", constraints_path) # Run py.test against the unit tests. session.run( @@ -139,6 +186,35 @@ def unit(session): default(session) +def install_systemtest_dependencies(session, *constraints): + + # Use pre-release gRPC for system tests. + session.install("--pre", "grpcio") + + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_LOCAL_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTRAS_BY_PYTHON: + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif SYSTEM_TEST_EXTRAS: + extras = SYSTEM_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" @@ -169,13 +245,7 @@ def system(session): if not system_test_exists and not system_test_folder_exists: session.skip("System tests were not found") - # Use pre-release gRPC for system tests. - session.install("--pre", "grpcio") - - # Install all test dependencies, then install this package into the - # virtualenv's dist-packages. - session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) - session.install("-e", ".[tracing]", "-c", constraints_path) + install_systemtest_dependencies(session, "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: diff --git a/owlbot.py b/owlbot.py index 673a1a8a70..a3a048fffb 100644 --- a/owlbot.py +++ b/owlbot.py @@ -137,14 +137,19 @@ def get_staging_dirs( # Add templated files # ---------------------------------------------------------------------------- templated_files = common.py_library( - microgenerator=True, samples=True, cov_level=99, split_system_tests=True, + microgenerator=True, + samples=True, + cov_level=99, + split_system_tests=True, + system_test_extras=["tracing"], ) -s.move(templated_files, +s.move( + templated_files, excludes=[ - ".coveragerc", - ".github/workflows", # exclude gh actions as credentials are needed for tests - ] - ) + ".coveragerc", + ".github/workflows", # exclude gh actions as credentials are needed for tests + ], +) # Ensure CI runs on a new instance each time s.replace( @@ -160,6 +165,7 @@ def get_staging_dirs( # Update samples folder in CONTRIBUTING.rst s.replace("CONTRIBUTING.rst", "samples/snippets", "samples/samples") +python.configure_previous_major_version_branches() # ---------------------------------------------------------------------------- # Samples templates # ---------------------------------------------------------------------------- diff --git a/samples/generated_samples/snippet_metadata_spanner admin database_v1.json b/samples/generated_samples/snippet_metadata_spanner admin database_v1.json new file mode 100644 index 0000000000..8487879c25 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_spanner admin database_v1.json @@ -0,0 +1,2988 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.spanner.admin.database.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-spanner-admin-database" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.copy_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CopyBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CopyBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "source_backup", + "type": "str" + }, + { + "name": "expire_time", + "type": "google.protobuf.timestamp_pb2.Timestamp" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "copy_backup" + }, + "description": "Sample for CopyBackup", + "file": "spanner_v1_generated_database_admin_copy_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CopyBackup_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_copy_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.copy_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CopyBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CopyBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "source_backup", + "type": "str" + }, + { + "name": "expire_time", + "type": "google.protobuf.timestamp_pb2.Timestamp" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "copy_backup" + }, + "description": "Sample for CopyBackup", + "file": "spanner_v1_generated_database_admin_copy_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CopyBackup_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_copy_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.create_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_backup" + }, + "description": "Sample for CreateBackup", + "file": "spanner_v1_generated_database_admin_create_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateBackup_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.create_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_backup" + }, + "description": "Sample for CreateBackup", + "file": "spanner_v1_generated_database_admin_create_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateBackup_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.create_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "create_statement", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_database" + }, + "description": "Sample for CreateDatabase", + "file": "spanner_v1_generated_database_admin_create_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateDatabase_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.create_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "create_statement", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_database" + }, + "description": "Sample for CreateDatabase", + "file": "spanner_v1_generated_database_admin_create_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.delete_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DeleteBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_backup" + }, + "description": "Sample for DeleteBackup", + "file": "spanner_v1_generated_database_admin_delete_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DeleteBackup_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_delete_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.delete_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DeleteBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_backup" + }, + "description": "Sample for DeleteBackup", + "file": "spanner_v1_generated_database_admin_delete_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_delete_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.drop_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DropDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "drop_database" + }, + "description": "Sample for DropDatabase", + "file": "spanner_v1_generated_database_admin_drop_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DropDatabase_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_drop_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.drop_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DropDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "drop_database" + }, + "description": "Sample for DropDatabase", + "file": "spanner_v1_generated_database_admin_drop_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DropDatabase_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_drop_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "get_backup" + }, + "description": "Sample for GetBackup", + "file": "spanner_v1_generated_database_admin_get_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetBackup_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "get_backup" + }, + "description": "Sample for GetBackup", + "file": "spanner_v1_generated_database_admin_get_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetBackup_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse", + "shortName": "get_database_ddl" + }, + "description": "Sample for GetDatabaseDdl", + "file": "spanner_v1_generated_database_admin_get_database_ddl_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_ddl_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse", + "shortName": "get_database_ddl" + }, + "description": "Sample for GetDatabaseDdl", + "file": "spanner_v1_generated_database_admin_get_database_ddl_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_ddl_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Database", + "shortName": "get_database" + }, + "description": "Sample for GetDatabase", + "file": "spanner_v1_generated_database_admin_get_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabase_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Database", + "shortName": "get_database" + }, + "description": "Sample for GetDatabase", + "file": "spanner_v1_generated_database_admin_get_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabase_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_database_admin_get_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_database_admin_get_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_backup_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackupOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsAsyncPager", + "shortName": "list_backup_operations" + }, + "description": "Sample for ListBackupOperations", + "file": "spanner_v1_generated_database_admin_list_backup_operations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backup_operations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_backup_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackupOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsPager", + "shortName": "list_backup_operations" + }, + "description": "Sample for ListBackupOperations", + "file": "spanner_v1_generated_database_admin_list_backup_operations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backup_operations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_backups", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackups", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackups" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsAsyncPager", + "shortName": "list_backups" + }, + "description": "Sample for ListBackups", + "file": "spanner_v1_generated_database_admin_list_backups_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackups_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backups_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_backups", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackups", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackups" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsPager", + "shortName": "list_backups" + }, + "description": "Sample for ListBackups", + "file": "spanner_v1_generated_database_admin_list_backups_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackups_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backups_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_database_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabaseOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsAsyncPager", + "shortName": "list_database_operations" + }, + "description": "Sample for ListDatabaseOperations", + "file": "spanner_v1_generated_database_admin_list_database_operations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_database_operations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_database_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabaseOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsPager", + "shortName": "list_database_operations" + }, + "description": "Sample for ListDatabaseOperations", + "file": "spanner_v1_generated_database_admin_list_database_operations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_database_operations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_databases", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesAsyncPager", + "shortName": "list_databases" + }, + "description": "Sample for ListDatabases", + "file": "spanner_v1_generated_database_admin_list_databases_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabases_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_databases_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_databases", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesPager", + "shortName": "list_databases" + }, + "description": "Sample for ListDatabases", + "file": "spanner_v1_generated_database_admin_list_databases_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabases_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_databases_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.restore_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "RestoreDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "database_id", + "type": "str" + }, + { + "name": "backup", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "restore_database" + }, + "description": "Sample for RestoreDatabase", + "file": "spanner_v1_generated_database_admin_restore_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_restore_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.restore_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "RestoreDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "database_id", + "type": "str" + }, + { + "name": "backup", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "restore_database" + }, + "description": "Sample for RestoreDatabase", + "file": "spanner_v1_generated_database_admin_restore_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_restore_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_database_admin_set_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_set_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_database_admin_set_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_set_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_database_admin_test_iam_permissions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_test_iam_permissions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_database_admin_test_iam_permissions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_test_iam_permissions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "update_backup" + }, + "description": "Sample for UpdateBackup", + "file": "spanner_v1_generated_database_admin_update_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateBackup_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "update_backup" + }, + "description": "Sample for UpdateBackup", + "file": "spanner_v1_generated_database_admin_update_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "statements", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_database_ddl" + }, + "description": "Sample for UpdateDatabaseDdl", + "file": "spanner_v1_generated_database_admin_update_database_ddl_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_ddl_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "statements", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_database_ddl" + }, + "description": "Sample for UpdateDatabaseDdl", + "file": "spanner_v1_generated_database_admin_update_database_ddl_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_ddl_sync.py" + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json b/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json new file mode 100644 index 0000000000..fbdf96b9c7 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_spanner admin instance_v1.json @@ -0,0 +1,1650 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.spanner.admin.instance.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-spanner-admin-instance" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.create_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_id", + "type": "str" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_instance" + }, + "description": "Sample for CreateInstance", + "file": "spanner_v1_generated_instance_admin_create_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstance_async", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.create_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_id", + "type": "str" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_instance" + }, + "description": "Sample for CreateInstance", + "file": "spanner_v1_generated_instance_admin_create_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstance_sync", + "segments": [ + { + "end": 55, + "start": 27, + "type": "FULL" + }, + { + "end": 55, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 52, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 56, + "start": 53, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.delete_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance" + }, + "description": "Sample for DeleteInstance", + "file": "spanner_v1_generated_instance_admin_delete_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstance_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.delete_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance" + }, + "description": "Sample for DeleteInstance", + "file": "spanner_v1_generated_instance_admin_delete_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstance_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_instance_admin_get_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", + "shortName": "get_instance_config" + }, + "description": "Sample for GetInstanceConfig", + "file": "spanner_v1_generated_instance_admin_get_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", + "shortName": "get_instance_config" + }, + "description": "Sample for GetInstanceConfig", + "file": "spanner_v1_generated_instance_admin_get_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_config_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", + "shortName": "get_instance" + }, + "description": "Sample for GetInstance", + "file": "spanner_v1_generated_instance_admin_get_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", + "shortName": "get_instance" + }, + "description": "Sample for GetInstance", + "file": "spanner_v1_generated_instance_admin_get_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instance_configs", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstanceConfigs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsAsyncPager", + "shortName": "list_instance_configs" + }, + "description": "Sample for ListInstanceConfigs", + "file": "spanner_v1_generated_instance_admin_list_instance_configs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instance_configs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instance_configs", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstanceConfigs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager", + "shortName": "list_instance_configs" + }, + "description": "Sample for ListInstanceConfigs", + "file": "spanner_v1_generated_instance_admin_list_instance_configs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instance_configs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instances", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstances", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstances" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesAsyncPager", + "shortName": "list_instances" + }, + "description": "Sample for ListInstances", + "file": "spanner_v1_generated_instance_admin_list_instances_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstances_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instances_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instances", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstances", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstances" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager", + "shortName": "list_instances" + }, + "description": "Sample for ListInstances", + "file": "spanner_v1_generated_instance_admin_list_instances_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstances_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instances_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_instance_admin_set_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_SetIamPolicy_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_set_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_instance_admin_set_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_set_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_instance_admin_test_iam_permissions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_TestIamPermissions_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_test_iam_permissions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 34, + "start": 32, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 35, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.update_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "field_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_instance" + }, + "description": "Sample for UpdateInstance", + "file": "spanner_v1_generated_instance_admin_update_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstance_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.update_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "field_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_instance" + }, + "description": "Sample for UpdateInstance", + "file": "spanner_v1_generated_instance_admin_update_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstance_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_sync.py" + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_spanner_v1.json b/samples/generated_samples/snippet_metadata_spanner_v1.json new file mode 100644 index 0000000000..5eb8233307 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_spanner_v1.json @@ -0,0 +1,2409 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.spanner.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-spanner" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.batch_create_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.BatchCreateSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BatchCreateSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BatchCreateSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "session_count", + "type": "int" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.BatchCreateSessionsResponse", + "shortName": "batch_create_sessions" + }, + "description": "Sample for BatchCreateSessions", + "file": "spanner_v1_generated_spanner_batch_create_sessions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BatchCreateSessions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_batch_create_sessions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.batch_create_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.BatchCreateSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BatchCreateSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BatchCreateSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "session_count", + "type": "int" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.BatchCreateSessionsResponse", + "shortName": "batch_create_sessions" + }, + "description": "Sample for BatchCreateSessions", + "file": "spanner_v1_generated_spanner_batch_create_sessions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BatchCreateSessions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_batch_create_sessions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.begin_transaction", + "method": { + "fullName": "google.spanner.v1.Spanner.BeginTransaction", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BeginTransaction" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BeginTransactionRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "options", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Transaction", + "shortName": "begin_transaction" + }, + "description": "Sample for BeginTransaction", + "file": "spanner_v1_generated_spanner_begin_transaction_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BeginTransaction_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_begin_transaction_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.begin_transaction", + "method": { + "fullName": "google.spanner.v1.Spanner.BeginTransaction", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BeginTransaction" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BeginTransactionRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "options", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Transaction", + "shortName": "begin_transaction" + }, + "description": "Sample for BeginTransaction", + "file": "spanner_v1_generated_spanner_begin_transaction_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BeginTransaction_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_begin_transaction_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.commit", + "method": { + "fullName": "google.spanner.v1.Spanner.Commit", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Commit" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CommitRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "mutations", + "type": "Sequence[google.cloud.spanner_v1.types.Mutation]" + }, + { + "name": "single_use_transaction", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.CommitResponse", + "shortName": "commit" + }, + "description": "Sample for Commit", + "file": "spanner_v1_generated_spanner_commit_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Commit_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_commit_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.commit", + "method": { + "fullName": "google.spanner.v1.Spanner.Commit", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Commit" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CommitRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "mutations", + "type": "Sequence[google.cloud.spanner_v1.types.Mutation]" + }, + { + "name": "single_use_transaction", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.CommitResponse", + "shortName": "commit" + }, + "description": "Sample for Commit", + "file": "spanner_v1_generated_spanner_commit_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Commit_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_commit_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.create_session", + "method": { + "fullName": "google.spanner.v1.Spanner.CreateSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "CreateSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CreateSessionRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "create_session" + }, + "description": "Sample for CreateSession", + "file": "spanner_v1_generated_spanner_create_session_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_CreateSession_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_create_session_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.create_session", + "method": { + "fullName": "google.spanner.v1.Spanner.CreateSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "CreateSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CreateSessionRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "create_session" + }, + "description": "Sample for CreateSession", + "file": "spanner_v1_generated_spanner_create_session_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_CreateSession_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_create_session_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.delete_session", + "method": { + "fullName": "google.spanner.v1.Spanner.DeleteSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "DeleteSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.DeleteSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_session" + }, + "description": "Sample for DeleteSession", + "file": "spanner_v1_generated_spanner_delete_session_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_DeleteSession_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_delete_session_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.delete_session", + "method": { + "fullName": "google.spanner.v1.Spanner.DeleteSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "DeleteSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.DeleteSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_session" + }, + "description": "Sample for DeleteSession", + "file": "spanner_v1_generated_spanner_delete_session_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_DeleteSession_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_delete_session_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_batch_dml", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteBatchDml", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteBatchDml" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteBatchDmlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ExecuteBatchDmlResponse", + "shortName": "execute_batch_dml" + }, + "description": "Sample for ExecuteBatchDml", + "file": "spanner_v1_generated_spanner_execute_batch_dml_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteBatchDml_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_batch_dml_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.execute_batch_dml", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteBatchDml", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteBatchDml" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteBatchDmlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ExecuteBatchDmlResponse", + "shortName": "execute_batch_dml" + }, + "description": "Sample for ExecuteBatchDml", + "file": "spanner_v1_generated_spanner_execute_batch_dml_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteBatchDml_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_batch_dml_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "execute_sql" + }, + "description": "Sample for ExecuteSql", + "file": "spanner_v1_generated_spanner_execute_sql_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteSql_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_sql_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.execute_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "execute_sql" + }, + "description": "Sample for ExecuteSql", + "file": "spanner_v1_generated_spanner_execute_sql_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteSql_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_sql_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_streaming_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteStreamingSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteStreamingSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "execute_streaming_sql" + }, + "description": "Sample for ExecuteStreamingSql", + "file": "spanner_v1_generated_spanner_execute_streaming_sql_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteStreamingSql_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_streaming_sql_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.execute_streaming_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteStreamingSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteStreamingSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "execute_streaming_sql" + }, + "description": "Sample for ExecuteStreamingSql", + "file": "spanner_v1_generated_spanner_execute_streaming_sql_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteStreamingSql_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_streaming_sql_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.get_session", + "method": { + "fullName": "google.spanner.v1.Spanner.GetSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "GetSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.GetSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "get_session" + }, + "description": "Sample for GetSession", + "file": "spanner_v1_generated_spanner_get_session_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_GetSession_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_get_session_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.get_session", + "method": { + "fullName": "google.spanner.v1.Spanner.GetSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "GetSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.GetSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "get_session" + }, + "description": "Sample for GetSession", + "file": "spanner_v1_generated_spanner_get_session_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_GetSession_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_get_session_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.list_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.ListSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ListSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ListSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.services.spanner.pagers.ListSessionsAsyncPager", + "shortName": "list_sessions" + }, + "description": "Sample for ListSessions", + "file": "spanner_v1_generated_spanner_list_sessions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ListSessions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_list_sessions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.list_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.ListSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ListSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ListSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.services.spanner.pagers.ListSessionsPager", + "shortName": "list_sessions" + }, + "description": "Sample for ListSessions", + "file": "spanner_v1_generated_spanner_list_sessions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ListSessions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_list_sessions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.partition_query", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionQuery", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionQuery" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionQueryRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_query" + }, + "description": "Sample for PartitionQuery", + "file": "spanner_v1_generated_spanner_partition_query_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionQuery_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_query_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.partition_query", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionQuery", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionQuery" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionQueryRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_query" + }, + "description": "Sample for PartitionQuery", + "file": "spanner_v1_generated_spanner_partition_query_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionQuery_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_query_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.partition_read", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_read" + }, + "description": "Sample for PartitionRead", + "file": "spanner_v1_generated_spanner_partition_read_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionRead_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_read_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.partition_read", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_read" + }, + "description": "Sample for PartitionRead", + "file": "spanner_v1_generated_spanner_partition_read_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionRead_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_read_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.read", + "method": { + "fullName": "google.spanner.v1.Spanner.Read", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Read" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "read" + }, + "description": "Sample for Read", + "file": "spanner_v1_generated_spanner_read_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Read_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_read_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.read", + "method": { + "fullName": "google.spanner.v1.Spanner.Read", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Read" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "read" + }, + "description": "Sample for Read", + "file": "spanner_v1_generated_spanner_read_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Read_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_read_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.rollback", + "method": { + "fullName": "google.spanner.v1.Spanner.Rollback", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Rollback" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.RollbackRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "rollback" + }, + "description": "Sample for Rollback", + "file": "spanner_v1_generated_spanner_rollback_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Rollback_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_rollback_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.rollback", + "method": { + "fullName": "google.spanner.v1.Spanner.Rollback", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Rollback" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.RollbackRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "rollback" + }, + "description": "Sample for Rollback", + "file": "spanner_v1_generated_spanner_rollback_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Rollback_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_rollback_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.streaming_read", + "method": { + "fullName": "google.spanner.v1.Spanner.StreamingRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "StreamingRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "streaming_read" + }, + "description": "Sample for StreamingRead", + "file": "spanner_v1_generated_spanner_streaming_read_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_StreamingRead_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_streaming_read_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.streaming_read", + "method": { + "fullName": "google.spanner.v1.Spanner.StreamingRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "StreamingRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "streaming_read" + }, + "description": "Sample for StreamingRead", + "file": "spanner_v1_generated_spanner_streaming_read_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_StreamingRead_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 43, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 44, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_streaming_read_sync.py" + } + ] +} diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py new file mode 100644 index 0000000000..645e606faf --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CopyBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CopyBackup_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CopyBackup_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py new file mode 100644 index 0000000000..f5babd289c --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CopyBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CopyBackup_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CopyBackup_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py new file mode 100644 index 0000000000..a1be785e1c --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateBackup_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateBackup_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py new file mode 100644 index 0000000000..1a7ce9f8ca --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateBackup_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateBackup_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py new file mode 100644 index 0000000000..fced822103 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateDatabase_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateDatabase_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py new file mode 100644 index 0000000000..27675447f5 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py new file mode 100644 index 0000000000..4d59be06df --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DeleteBackup_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + await client.delete_backup(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DeleteBackup_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py new file mode 100644 index 0000000000..7f4ed7f95a --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + client.delete_backup(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py new file mode 100644 index 0000000000..245fbacffb --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DropDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DropDatabase_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + await client.drop_database(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DropDatabase_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py new file mode 100644 index 0000000000..d710e77dbb --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DropDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DropDatabase_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + client.drop_database(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DropDatabase_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py new file mode 100644 index 0000000000..a0fa4faa37 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetBackup_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = await client.get_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetBackup_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py new file mode 100644 index 0000000000..fa1b735014 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetBackup_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = client.get_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetBackup_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py new file mode 100644 index 0000000000..37056a3efc --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabase_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = await client.get_database(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabase_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py new file mode 100644 index 0000000000..ece964619b --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = await client.get_database_ddl(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py new file mode 100644 index 0000000000..4272b0eb3d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = client.get_database_ddl(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py new file mode 100644 index 0000000000..a1800f30bc --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabase_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = client.get_database(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabase_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py new file mode 100644 index 0000000000..1959177243 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async] +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py new file mode 100644 index 0000000000..9be30edfd6 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync] +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py new file mode 100644 index 0000000000..bf5ec734d2 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackupOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py new file mode 100644 index 0000000000..5bc5aeaa12 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackupOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py new file mode 100644 index 0000000000..26cfe9ec7d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackups +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackups_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackups_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py new file mode 100644 index 0000000000..6857e7d320 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackups +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackups_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackups_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py new file mode 100644 index 0000000000..261110f5bd --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabaseOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py new file mode 100644 index 0000000000..b9b8b55b02 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabaseOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py new file mode 100644 index 0000000000..5e718ee39f --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabases_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabases_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py new file mode 100644 index 0000000000..ddab069f91 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabases_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabases_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py new file mode 100644 index 0000000000..4aaec9b90c --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RestoreDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py new file mode 100644 index 0000000000..4cba97cec2 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RestoreDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py new file mode 100644 index 0000000000..98c7e11f73 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async] +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py new file mode 100644 index 0000000000..7afb87925a --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync] +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py new file mode 100644 index 0000000000..9708cba8b0 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async] +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py new file mode 100644 index 0000000000..b0aa0f62fb --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync] +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py new file mode 100644 index 0000000000..569e68395f --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateBackup_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = await client.update_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateBackup_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py new file mode 100644 index 0000000000..40613c1f0b --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = client.update_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py new file mode 100644 index 0000000000..2d16052746 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async] +from google.cloud import spanner_admin_database_v1 + + +async def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value_1', 'statements_value_2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async] diff --git a/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py new file mode 100644 index 0000000000..019b739cff --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync] +from google.cloud import spanner_admin_database_v1 + + +def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value_1', 'statements_value_2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py new file mode 100644 index 0000000000..f9cc40553b --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstance_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstance_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py new file mode 100644 index 0000000000..298a6fb34d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstance_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstance_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py new file mode 100644 index 0000000000..84054f0e00 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstance_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstance_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py new file mode 100644 index 0000000000..7cf64b0a36 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstance_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + client.delete_instance(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstance_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py new file mode 100644 index 0000000000..d052e15b6d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetIamPolicy_async] +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetIamPolicy_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py new file mode 100644 index 0000000000..0c172f5b8d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync] +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py new file mode 100644 index 0000000000..50093013d4 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstance_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstance_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py new file mode 100644 index 0000000000..7b620f61e1 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance_config(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py new file mode 100644 index 0000000000..50691dbcdb --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_config(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py new file mode 100644 index 0000000000..f7a2ea1323 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstance_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstance_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py new file mode 100644 index 0000000000..b330645135 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstanceConfigs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py new file mode 100644 index 0000000000..a2309f6d91 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstanceConfigs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py new file mode 100644 index 0000000000..138993f116 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstances +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstances_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstances_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py new file mode 100644 index 0000000000..88dfd120e8 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstances +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstances_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstances_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py new file mode 100644 index 0000000000..25d90383d8 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_SetIamPolicy_async] +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_SetIamPolicy_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py new file mode 100644 index 0000000000..76ae1c544d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync] +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py new file mode 100644 index 0000000000..0669b2b8b6 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_TestIamPermissions_async] +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_TestIamPermissions_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py new file mode 100644 index 0000000000..a2bad7d92b --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync] +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value_1', 'permissions_value_2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py new file mode 100644 index 0000000000..a6a3c5e756 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstance_async] +from google.cloud import spanner_admin_instance_v1 + + +async def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstance_async] diff --git a/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py new file mode 100644 index 0000000000..90160a2cc1 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstance_sync] +from google.cloud import spanner_admin_instance_v1 + + +def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstance_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py b/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py new file mode 100644 index 0000000000..78f195c393 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BatchCreateSessions_async] +from google.cloud import spanner_v1 + + +async def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = await client.batch_create_sessions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BatchCreateSessions_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py new file mode 100644 index 0000000000..2842953afd --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BatchCreateSessions_sync] +from google.cloud import spanner_v1 + + +def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = client.batch_create_sessions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BatchCreateSessions_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py b/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py new file mode 100644 index 0000000000..90a1fd1e00 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BeginTransaction +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BeginTransaction_async] +from google.cloud import spanner_v1 + + +async def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = await client.begin_transaction(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BeginTransaction_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py new file mode 100644 index 0000000000..43d5ff0dc1 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BeginTransaction +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BeginTransaction_sync] +from google.cloud import spanner_v1 + + +def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = client.begin_transaction(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BeginTransaction_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py b/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py new file mode 100644 index 0000000000..354d44fc0f --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Commit +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Commit_async] +from google.cloud import spanner_v1 + + +async def sample_commit(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = await client.commit(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Commit_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py new file mode 100644 index 0000000000..ae1969c464 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Commit +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Commit_sync] +from google.cloud import spanner_v1 + + +def sample_commit(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = client.commit(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Commit_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py b/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py new file mode 100644 index 0000000000..2536506397 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_CreateSession_async] +from google.cloud import spanner_v1 + + +async def sample_create_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = await client.create_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_CreateSession_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py new file mode 100644 index 0000000000..5d457e4f9c --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_CreateSession_sync] +from google.cloud import spanner_v1 + + +def sample_create_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = client.create_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_CreateSession_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py b/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py new file mode 100644 index 0000000000..1493a78beb --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_DeleteSession_async] +from google.cloud import spanner_v1 + + +async def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + await client.delete_session(request=request) + + +# [END spanner_v1_generated_Spanner_DeleteSession_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py new file mode 100644 index 0000000000..f83f686fd7 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_DeleteSession_sync] +from google.cloud import spanner_v1 + + +def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + client.delete_session(request=request) + + +# [END spanner_v1_generated_Spanner_DeleteSession_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py b/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py new file mode 100644 index 0000000000..285f70d8d6 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteBatchDml +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteBatchDml_async] +from google.cloud import spanner_v1 + + +async def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = await client.execute_batch_dml(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteBatchDml_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py new file mode 100644 index 0000000000..1e4a448567 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteBatchDml +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteBatchDml_sync] +from google.cloud import spanner_v1 + + +def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = client.execute_batch_dml(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteBatchDml_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py b/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py new file mode 100644 index 0000000000..1d884903fb --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteSql_async] +from google.cloud import spanner_v1 + + +async def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = await client.execute_sql(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteSql_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py new file mode 100644 index 0000000000..361c30ed0d --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteSql_sync] +from google.cloud import spanner_v1 + + +def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.execute_sql(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteSql_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py b/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py new file mode 100644 index 0000000000..d47b3d55fc --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteStreamingSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteStreamingSql_async] +from google.cloud import spanner_v1 + + +async def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = await client.execute_streaming_sql(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteStreamingSql_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py new file mode 100644 index 0000000000..9265963da4 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteStreamingSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteStreamingSql_sync] +from google.cloud import spanner_v1 + + +def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = client.execute_streaming_sql(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteStreamingSql_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py b/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py new file mode 100644 index 0000000000..b274f4e949 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_GetSession_async] +from google.cloud import spanner_v1 + + +async def sample_get_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_GetSession_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py new file mode 100644 index 0000000000..d613f8b293 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_GetSession_sync] +from google.cloud import spanner_v1 + + +def sample_get_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = client.get_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_GetSession_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py b/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py new file mode 100644 index 0000000000..e3ba126ce6 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ListSessions_async] +from google.cloud import spanner_v1 + + +async def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_Spanner_ListSessions_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py new file mode 100644 index 0000000000..0bc0bac7d2 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ListSessions_sync] +from google.cloud import spanner_v1 + + +def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_Spanner_ListSessions_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py b/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py new file mode 100644 index 0000000000..4e0a22d7fc --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionQuery +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionQuery_async] +from google.cloud import spanner_v1 + + +async def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = await client.partition_query(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionQuery_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py new file mode 100644 index 0000000000..04af535cf3 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionQuery +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionQuery_sync] +from google.cloud import spanner_v1 + + +def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.partition_query(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionQuery_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py b/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py new file mode 100644 index 0000000000..ab35787e21 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionRead_async] +from google.cloud import spanner_v1 + + +async def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = await client.partition_read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionRead_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py new file mode 100644 index 0000000000..f5ccab3958 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionRead_sync] +from google.cloud import spanner_v1 + + +def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = client.partition_read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionRead_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_read_async.py b/samples/generated_samples/spanner_v1_generated_spanner_read_async.py new file mode 100644 index 0000000000..315cb067df --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_read_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Read +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Read_async] +from google.cloud import spanner_v1 + + +async def sample_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + response = await client.read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Read_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py new file mode 100644 index 0000000000..7fd4758d17 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Read +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Read_sync] +from google.cloud import spanner_v1 + + +def sample_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + response = client.read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Read_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py b/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py new file mode 100644 index 0000000000..926171e5fd --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Rollback +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Rollback_async] +from google.cloud import spanner_v1 + + +async def sample_rollback(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + await client.rollback(request=request) + + +# [END spanner_v1_generated_Spanner_Rollback_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py new file mode 100644 index 0000000000..3047b54984 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Rollback +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Rollback_sync] +from google.cloud import spanner_v1 + + +def sample_rollback(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + client.rollback(request=request) + + +# [END spanner_v1_generated_Spanner_Rollback_sync] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py b/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py new file mode 100644 index 0000000000..7f0139e3b7 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_StreamingRead_async] +from google.cloud import spanner_v1 + + +async def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + stream = await client.streaming_read(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_StreamingRead_async] diff --git a/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py b/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py new file mode 100644 index 0000000000..1484239348 --- /dev/null +++ b/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_StreamingRead_sync] +from google.cloud import spanner_v1 + + +def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value_1', 'columns_value_2'], + ) + + # Make the request + stream = client.streaming_read(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_StreamingRead_sync] diff --git a/samples/samples/autocommit.py b/samples/samples/autocommit.py index 873ed2b7bd..d5c44b0c53 100644 --- a/samples/samples/autocommit.py +++ b/samples/samples/autocommit.py @@ -46,14 +46,11 @@ def enable_autocommit_mode(instance_id, database_id): if __name__ == "__main__": parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument("instance_id", help="Your Cloud Spanner instance ID.") parser.add_argument( - "--database-id", - help="Your Cloud Spanner database ID.", - default="example_db", + "--database-id", help="Your Cloud Spanner database ID.", default="example_db", ) subparsers = parser.add_subparsers(dest="command") subparsers.add_parser("enable_autocommit_mode", help=enable_autocommit_mode.__doc__) diff --git a/samples/samples/autocommit_test.py b/samples/samples/autocommit_test.py index 9880460cac..6b102da8fe 100644 --- a/samples/samples/autocommit_test.py +++ b/samples/samples/autocommit_test.py @@ -19,7 +19,7 @@ def sample_name(): @RetryErrors(exception=Aborted, max_tries=2) def test_enable_autocommit_mode(capsys, instance_id, sample_database): # Delete table if it exists for retry attempts. - table = sample_database.table('Singers') + table = sample_database.table("Singers") if table.exists(): op = sample_database.update_ddl(["DROP TABLE Singers"]) op.result() diff --git a/samples/samples/backup_sample.py b/samples/samples/backup_sample.py index d22530c735..01d3e4bf60 100644 --- a/samples/samples/backup_sample.py +++ b/samples/samples/backup_sample.py @@ -34,7 +34,9 @@ def create_backup(instance_id, database_id, backup_id, version_time): # Create a backup expire_time = datetime.utcnow() + timedelta(days=14) - backup = instance.backup(backup_id, database=database, expire_time=expire_time, version_time=version_time) + backup = instance.backup( + backup_id, database=database, expire_time=expire_time, version_time=version_time + ) operation = backup.create() # Wait for backup operation to complete. @@ -56,7 +58,9 @@ def create_backup(instance_id, database_id, backup_id, version_time): # [END spanner_create_backup] # [START spanner_create_backup_with_encryption_key] -def create_backup_with_encryption_key(instance_id, database_id, backup_id, kms_key_name): +def create_backup_with_encryption_key( + instance_id, database_id, backup_id, kms_key_name +): """Creates a backup for a database using a Customer Managed Encryption Key (CMEK).""" from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig @@ -67,10 +71,15 @@ def create_backup_with_encryption_key(instance_id, database_id, backup_id, kms_k # Create a backup expire_time = datetime.utcnow() + timedelta(days=14) encryption_config = { - 'encryption_type': CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, - 'kms_key_name': kms_key_name, + "encryption_type": CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, + "kms_key_name": kms_key_name, } - backup = instance.backup(backup_id, database=database, expire_time=expire_time, encryption_config=encryption_config) + backup = instance.backup( + backup_id, + database=database, + expire_time=expire_time, + encryption_config=encryption_config, + ) operation = backup.create() # Wait for backup operation to complete. @@ -115,7 +124,7 @@ def restore_database(instance_id, new_database_id, backup_id): restore_info.backup_info.source_database, new_database_id, restore_info.backup_info.backup, - restore_info.backup_info.version_time + restore_info.backup_info.version_time, ) ) @@ -124,7 +133,9 @@ def restore_database(instance_id, new_database_id, backup_id): # [START spanner_restore_backup_with_encryption_key] -def restore_database_with_encryption_key(instance_id, new_database_id, backup_id, kms_key_name): +def restore_database_with_encryption_key( + instance_id, new_database_id, backup_id, kms_key_name +): """Restores a database from a backup using a Customer Managed Encryption Key (CMEK).""" from google.cloud.spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig @@ -134,10 +145,12 @@ def restore_database_with_encryption_key(instance_id, new_database_id, backup_id # Start restoring an existing backup to a new database. backup = instance.backup(backup_id) encryption_config = { - 'encryption_type': RestoreDatabaseEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, - 'kms_key_name': kms_key_name, + "encryption_type": RestoreDatabaseEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION, + "kms_key_name": kms_key_name, } - new_database = instance.database(new_database_id, encryption_config=encryption_config) + new_database = instance.database( + new_database_id, encryption_config=encryption_config + ) operation = new_database.restore(backup) # Wait for restore operation to complete. @@ -192,7 +205,7 @@ def cancel_backup(instance_id, database_id, backup_id): # [START spanner_list_backup_operations] -def list_backup_operations(instance_id, database_id): +def list_backup_operations(instance_id, database_id, backup_id): spanner_client = spanner.Client() instance = spanner_client.instance(instance_id) @@ -211,6 +224,22 @@ def list_backup_operations(instance_id, database_id): ) ) + # List the CopyBackup operations. + filter_ = ( + "(metadata.@type:type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) " + "AND (metadata.source_backup:{})" + ).format(backup_id) + operations = instance.list_backup_operations(filter_=filter_) + for op in operations: + metadata = op.metadata + print( + "Backup {} on source backup {}: {}% complete.".format( + metadata.name, + metadata.source_backup, + metadata.progress.progress_percent, + ) + ) + # [END spanner_list_backup_operations] @@ -291,8 +320,11 @@ def list_backups(instance_id, database_id, backup_id): print("All backups with pagination") # If there are multiple pages, additional ``ListBackup`` # requests will be made as needed while iterating. + paged_backups = set() for backup in instance.list_backups(page_size=2): - print(backup.name) + paged_backups.add(backup.name) + for backup in paged_backups: + print(backup) # [END spanner_list_backups] @@ -330,7 +362,8 @@ def update_backup(instance_id, backup_id): # Expire time must be within 366 days of the create time of the backup. old_expire_time = backup.expire_time - new_expire_time = old_expire_time + timedelta(days=30) + # New expire time should be less than the max expire time + new_expire_time = min(backup.max_expire_time, old_expire_time + timedelta(days=30)) backup.update_expire_time(new_expire_time) print( "Backup {} expire time was updated from {} to {}.".format( @@ -343,7 +376,9 @@ def update_backup(instance_id, backup_id): # [START spanner_create_database_with_version_retention_period] -def create_database_with_version_retention_period(instance_id, database_id, retention_period): +def create_database_with_version_retention_period( + instance_id, database_id, retention_period +): """Creates a database with a version retention period.""" spanner_client = spanner.Client() instance = spanner_client.instance(instance_id) @@ -363,7 +398,7 @@ def create_database_with_version_retention_period(instance_id, database_id, rete "ALTER DATABASE `{}`" " SET OPTIONS (version_retention_period = '{}')".format( database_id, retention_period - ) + ), ] db = instance.database(database_id, ddl_statements) operation = db.create() @@ -372,15 +407,51 @@ def create_database_with_version_retention_period(instance_id, database_id, rete db.reload() - print("Database {} created with version retention period {} and earliest version time {}".format( - db.database_id, db.version_retention_period, db.earliest_version_time - )) + print( + "Database {} created with version retention period {} and earliest version time {}".format( + db.database_id, db.version_retention_period, db.earliest_version_time + ) + ) db.drop() + # [END spanner_create_database_with_version_retention_period] +# [START spanner_copy_backup] +def copy_backup(instance_id, backup_id, source_backup_path): + """Copies a backup.""" + spanner_client = spanner.Client() + instance = spanner_client.instance(instance_id) + + # Create a backup object and wait for copy backup operation to complete. + expire_time = datetime.utcnow() + timedelta(days=14) + copy_backup = instance.copy_backup( + backup_id=backup_id, source_backup=source_backup_path, expire_time=expire_time + ) + operation = copy_backup.create() + + # Wait for copy backup operation to complete. + operation.result(2100) + + # Verify that the copy backup is ready. + copy_backup.reload() + assert copy_backup.is_ready() is True + + print( + "Backup {} of size {} bytes was created at {} with version time {}".format( + copy_backup.name, + copy_backup.size_bytes, + copy_backup.create_time, + copy_backup.version_time, + ) + ) + + +# [END spanner_copy_backup] + + if __name__ == "__main__": # noqa: C901 parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter @@ -404,6 +475,7 @@ def create_database_with_version_retention_period(instance_id, database_id, rete "list_database_operations", help=list_database_operations.__doc__ ) subparsers.add_parser("delete_backup", help=delete_backup.__doc__) + subparsers.add_parser("copy_backup", help=copy_backup.__doc__) args = parser.parse_args() @@ -418,10 +490,12 @@ def create_database_with_version_retention_period(instance_id, database_id, rete elif args.command == "list_backups": list_backups(args.instance_id, args.database_id, args.backup_id) elif args.command == "list_backup_operations": - list_backup_operations(args.instance_id, args.database_id) + list_backup_operations(args.instance_id, args.database_id, args.backup_id) elif args.command == "list_database_operations": list_database_operations(args.instance_id) elif args.command == "delete_backup": delete_backup(args.instance_id, args.backup_id) + elif args.command == "copy_backup": + copy_backup(args.instance_id, args.backup_id, args.source_backup_id) else: print("Command {} did not match expected commands.".format(args.command)) diff --git a/samples/samples/backup_sample_test.py b/samples/samples/backup_sample_test.py index 6d89dcf440..da50fbba46 100644 --- a/samples/samples/backup_sample_test.py +++ b/samples/samples/backup_sample_test.py @@ -41,6 +41,7 @@ def unique_backup_id(): CMEK_BACKUP_ID = unique_backup_id() RETENTION_DATABASE_ID = unique_database_id() RETENTION_PERIOD = "7d" +COPY_BACKUP_ID = unique_backup_id() @pytest.mark.dependency(name="create_backup") @@ -51,24 +52,32 @@ def test_create_backup(capsys, instance_id, sample_database): version_time = list(results)[0][0] backup_sample.create_backup( - instance_id, - sample_database.database_id, - BACKUP_ID, - version_time, + instance_id, sample_database.database_id, BACKUP_ID, version_time, ) out, _ = capsys.readouterr() assert BACKUP_ID in out +@pytest.mark.dependency(name="copy_backup", depends=["create_backup"]) +def test_copy_backup(capsys, instance_id, spanner_client): + source_backp_path = ( + spanner_client.project_name + + "/instances/" + + instance_id + + "/backups/" + + BACKUP_ID + ) + backup_sample.copy_backup(instance_id, COPY_BACKUP_ID, source_backp_path) + out, _ = capsys.readouterr() + assert COPY_BACKUP_ID in out + + @pytest.mark.dependency(name="create_backup_with_encryption_key") def test_create_backup_with_encryption_key( capsys, instance_id, sample_database, kms_key_name, ): backup_sample.create_backup_with_encryption_key( - instance_id, - sample_database.database_id, - CMEK_BACKUP_ID, - kms_key_name, + instance_id, sample_database.database_id, CMEK_BACKUP_ID, kms_key_name, ) out, _ = capsys.readouterr() assert CMEK_BACKUP_ID in out @@ -91,7 +100,8 @@ def test_restore_database_with_encryption_key( capsys, instance_id, sample_database, kms_key_name, ): backup_sample.restore_database_with_encryption_key( - instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_name) + instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_name + ) out, _ = capsys.readouterr() assert (sample_database.database_id + " restored to ") in out assert (CMEK_RESTORE_DB_ID + " from backup ") in out @@ -99,17 +109,22 @@ def test_restore_database_with_encryption_key( assert kms_key_name in out -@pytest.mark.dependency(depends=["create_backup"]) +@pytest.mark.dependency(depends=["create_backup", "copy_backup"]) def test_list_backup_operations(capsys, instance_id, sample_database): backup_sample.list_backup_operations( - instance_id, sample_database.database_id) + instance_id, sample_database.database_id, BACKUP_ID + ) out, _ = capsys.readouterr() assert BACKUP_ID in out assert sample_database.database_id in out + assert COPY_BACKUP_ID in out + print(out) -@pytest.mark.dependency(depends=["create_backup"]) -def test_list_backups(capsys, instance_id, sample_database): +@pytest.mark.dependency(name="list_backup", depends=["create_backup", "copy_backup"]) +def test_list_backups( + capsys, instance_id, sample_database, +): backup_sample.list_backups( instance_id, sample_database.database_id, BACKUP_ID, ) @@ -125,11 +140,14 @@ def test_update_backup(capsys, instance_id): assert BACKUP_ID in out -@pytest.mark.dependency(depends=["create_backup"]) +@pytest.mark.dependency(depends=["create_backup", "copy_backup", "list_backup"]) def test_delete_backup(capsys, instance_id): backup_sample.delete_backup(instance_id, BACKUP_ID) out, _ = capsys.readouterr() assert BACKUP_ID in out + backup_sample.delete_backup(instance_id, COPY_BACKUP_ID) + out, _ = capsys.readouterr() + assert COPY_BACKUP_ID in out @pytest.mark.dependency(depends=["create_backup"]) diff --git a/samples/samples/conftest.py b/samples/samples/conftest.py index b3728a4db4..314c984920 100644 --- a/samples/samples/conftest.py +++ b/samples/samples/conftest.py @@ -93,9 +93,7 @@ def instance_config(spanner_client): @pytest.fixture(scope="module") def multi_region_instance_config(spanner_client): - return "{}/instanceConfigs/{}".format( - spanner_client.project_name, "nam3" - ) + return "{}/instanceConfigs/{}".format(spanner_client.project_name, "nam3") @pytest.fixture(scope="module") @@ -143,7 +141,7 @@ def multi_region_instance( labels={ "cloud_spanner_samples": "true", "sample_name": sample_name, - "created": str(int(time.time())) + "created": str(int(time.time())), }, ) op = retry_429(multi_region_instance.create)() diff --git a/samples/samples/noxfile.py b/samples/samples/noxfile.py index 20cdfc6201..949e0fde9a 100644 --- a/samples/samples/noxfile.py +++ b/samples/samples/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -188,42 +188,54 @@ def _session_tests( # check for presence of tests test_list = glob.glob("*_test.py") + glob.glob("test_*.py") test_list.extend(glob.glob("tests")) + if len(test_list) == 0: print("No tests found, skipping directory.") - else: - if TEST_CONFIG["pip_version_override"]: - pip_version = TEST_CONFIG["pip_version_override"] - session.install(f"pip=={pip_version}") - """Runs py.test for a particular project.""" - if os.path.exists("requirements.txt"): - if os.path.exists("constraints.txt"): - session.install("-r", "requirements.txt", "-c", "constraints.txt") - else: - session.install("-r", "requirements.txt") - - if os.path.exists("requirements-test.txt"): - if os.path.exists("constraints-test.txt"): - session.install( - "-r", "requirements-test.txt", "-c", "constraints-test.txt" - ) - else: - session.install("-r", "requirements-test.txt") - - if INSTALL_LIBRARY_FROM_SOURCE: - session.install("-e", _get_repo_root()) - - if post_install: - post_install(session) - - session.run( - "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), - # Pytest will return 5 when no tests are collected. This can happen - # on travis where slow and flaky tests are excluded. - # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html - success_codes=[0, 5], - env=get_pytest_env_vars(), - ) + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + elif "pytest-xdist" in packages: + concurrent_args.extend(['-n', 'auto']) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) @nox.session(python=ALL_VERSIONS) diff --git a/samples/samples/requirements-test.txt b/samples/samples/requirements-test.txt index e18a125cd8..3d42f3a24a 100644 --- a/samples/samples/requirements-test.txt +++ b/samples/samples/requirements-test.txt @@ -1,4 +1,4 @@ -pytest==6.2.5 +pytest==7.1.1 pytest-dependency==0.5.1 mock==4.0.3 google-cloud-testutils==1.3.1 diff --git a/samples/samples/requirements.txt b/samples/samples/requirements.txt index c5b7ca5fc5..c2b585853e 100644 --- a/samples/samples/requirements.txt +++ b/samples/samples/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-spanner==3.12.1 +google-cloud-spanner==3.13.0 futures==3.3.0; python_version < "3" diff --git a/samples/samples/snippets.py b/samples/samples/snippets.py index 5a3ac6df24..87721c021f 100644 --- a/samples/samples/snippets.py +++ b/samples/samples/snippets.py @@ -51,8 +51,8 @@ def create_instance(instance_id): labels={ "cloud_spanner_samples": "true", "sample_name": "snippets-create_instance-explicit", - "created": str(int(time.time())) - } + "created": str(int(time.time())), + }, ) operation = instance.create() @@ -83,8 +83,8 @@ def create_instance_with_processing_units(instance_id, processing_units): labels={ "cloud_spanner_samples": "true", "sample_name": "snippets-create_instance_with_processing_units", - "created": str(int(time.time())) - } + "created": str(int(time.time())), + }, ) operation = instance.create() @@ -92,8 +92,11 @@ def create_instance_with_processing_units(instance_id, processing_units): print("Waiting for operation to complete...") operation.result(OPERATION_TIMEOUT_SECONDS) - print("Created instance {} with {} processing units".format( - instance_id, instance.processing_units)) + print( + "Created instance {} with {} processing units".format( + instance_id, instance.processing_units + ) + ) # [END spanner_create_instance_with_processing_units] @@ -103,10 +106,15 @@ def create_instance_with_processing_units(instance_id, processing_units): def get_instance_config(instance_config): """Gets the leader options for the instance configuration.""" spanner_client = spanner.Client() - config_name = "{}/instanceConfigs/{}".format(spanner_client.project_name, instance_config) + config_name = "{}/instanceConfigs/{}".format( + spanner_client.project_name, instance_config + ) config = spanner_client.instance_admin_api.get_instance_config(name=config_name) - print("Available leader options for instance config {}: {}".format( - instance_config, config.leader_options)) + print( + "Available leader options for instance config {}: {}".format( + instance_config, config.leader_options + ) + ) # [END spanner_get_instance_config] @@ -203,7 +211,7 @@ def create_database_with_encryption_key(instance_id, database_id, kms_key_name): ) PRIMARY KEY (SingerId, AlbumId), INTERLEAVE IN PARENT Singers ON DELETE CASCADE""", ], - encryption_config={'kms_key_name': kms_key_name}, + encryption_config={"kms_key_name": kms_key_name}, ) operation = database.create() @@ -211,17 +219,18 @@ def create_database_with_encryption_key(instance_id, database_id, kms_key_name): print("Waiting for operation to complete...") operation.result(OPERATION_TIMEOUT_SECONDS) - print("Database {} created with encryption key {}".format( - database.name, database.encryption_config.kms_key_name)) + print( + "Database {} created with encryption key {}".format( + database.name, database.encryption_config.kms_key_name + ) + ) # [END spanner_create_database_with_encryption_key] # [START spanner_create_database_with_default_leader] -def create_database_with_default_leader( - instance_id, database_id, default_leader -): +def create_database_with_default_leader(instance_id, database_id, default_leader): """Creates a database with tables with a default leader.""" spanner_client = spanner.Client() instance = spanner_client.instance(instance_id) @@ -254,7 +263,7 @@ def create_database_with_default_leader( print( "Database {} created with default leader {}".format( - database.name, database.default_leader + database.name, database.default_leader ) ) @@ -263,17 +272,19 @@ def create_database_with_default_leader( # [START spanner_update_database_with_default_leader] -def update_database_with_default_leader( - instance_id, database_id, default_leader -): +def update_database_with_default_leader(instance_id, database_id, default_leader): """Updates a database with tables with a default leader.""" spanner_client = spanner.Client() instance = spanner_client.instance(instance_id) database = instance.database(database_id) - operation = database.update_ddl(["ALTER DATABASE {}" - " SET OPTIONS (default_leader = '{}')".format(database_id, default_leader)]) + operation = database.update_ddl( + [ + "ALTER DATABASE {}" + " SET OPTIONS (default_leader = '{}')".format(database_id, default_leader) + ] + ) operation.result(OPERATION_TIMEOUT_SECONDS) database.reload() @@ -316,9 +327,7 @@ def query_information_schema_database_options(instance_id, database_id): "WHERE SCHEMA_NAME = '' AND OPTION_NAME = 'default_leader'" ) for result in results: - print("Database {} has default leader {}".format( - database_id, result[0] - )) + print("Database {} has default leader {}".format(database_id, result[0])) # [END spanner_query_information_schema_database_options] @@ -1307,11 +1316,9 @@ def insert_singers(transaction): database.run_in_transaction(insert_singers) commit_stats = database.logger.last_commit_stats - print( - "{} mutation(s) in transaction.".format( - commit_stats.mutation_count - ) - ) + print("{} mutation(s) in transaction.".format(commit_stats.mutation_count)) + + # [END spanner_get_commit_stats] @@ -2011,7 +2018,7 @@ def query_data_with_query_options(instance_id, database_id): "SELECT VenueId, VenueName, LastUpdateTime FROM Venues", query_options={ "optimizer_version": "1", - "optimizer_statistics_package": "latest" + "optimizer_statistics_package": "latest", }, ) @@ -2028,8 +2035,9 @@ def create_client_with_query_options(instance_id, database_id): spanner_client = spanner.Client( query_options={ "optimizer_version": "1", - "optimizer_statistics_package": "auto_20191128_14_47_22UTC" - }) + "optimizer_statistics_package": "auto_20191128_14_47_22UTC", + } + ) instance = spanner_client.instance(instance_id) database = instance.database(database_id) @@ -2057,7 +2065,7 @@ def update_venues(transaction): # This request tag will only be set on this request. transaction.execute_update( "UPDATE Venues SET Capacity = CAST(Capacity/4 AS INT64) WHERE OutdoorVenue = false", - request_options={"request_tag": "app=concert,env=dev,action=update"} + request_options={"request_tag": "app=concert,env=dev,action=update"}, ) print("Venue capacities updated.") @@ -2070,21 +2078,19 @@ def update_venues(transaction): "venueId": 81, "venueName": "Venue 81", "capacity": 1440, - "outdoorVenue": True + "outdoorVenue": True, }, param_types={ "venueId": param_types.INT64, "venueName": param_types.STRING, "capacity": param_types.INT64, - "outdoorVenue": param_types.BOOL + "outdoorVenue": param_types.BOOL, }, - request_options={"request_tag": "app=concert,env=dev,action=insert"} + request_options={"request_tag": "app=concert,env=dev,action=insert"}, ) print("New venue inserted.") - database.run_in_transaction( - update_venues, transaction_tag="app=concert,env=dev" - ) + database.run_in_transaction(update_venues, transaction_tag="app=concert,env=dev") # [END spanner_set_transaction_tag] @@ -2101,7 +2107,7 @@ def set_request_tag(instance_id, database_id): with database.snapshot() as snapshot: results = snapshot.execute_sql( "SELECT SingerId, AlbumId, AlbumTitle FROM Albums", - request_options={"request_tag": "app=concert,env=dev,action=select"} + request_options={"request_tag": "app=concert,env=dev,action=select"}, ) for row in results: diff --git a/samples/samples/snippets_test.py b/samples/samples/snippets_test.py index d81032fa20..a5fa6a5caf 100644 --- a/samples/samples/snippets_test.py +++ b/samples/samples/snippets_test.py @@ -124,8 +124,12 @@ def test_create_instance_with_processing_units(capsys, lci_instance_id): retry_429(instance.delete)() -def test_create_database_with_encryption_config(capsys, instance_id, cmek_database_id, kms_key_name): - snippets.create_database_with_encryption_key(instance_id, cmek_database_id, kms_key_name) +def test_create_database_with_encryption_config( + capsys, instance_id, cmek_database_id, kms_key_name +): + snippets.create_database_with_encryption_key( + instance_id, cmek_database_id, kms_key_name + ) out, _ = capsys.readouterr() assert cmek_database_id in out assert kms_key_name in out @@ -150,7 +154,13 @@ def test_list_databases(capsys, instance_id): assert "has default leader" in out -def test_create_database_with_default_leader(capsys, multi_region_instance, multi_region_instance_id, default_leader_database_id, default_leader): +def test_create_database_with_default_leader( + capsys, + multi_region_instance, + multi_region_instance_id, + default_leader_database_id, + default_leader, +): retry_429 = RetryErrors(exceptions.ResourceExhausted, delay=15) retry_429(snippets.create_database_with_default_leader)( multi_region_instance_id, default_leader_database_id, default_leader @@ -160,7 +170,13 @@ def test_create_database_with_default_leader(capsys, multi_region_instance, mult assert default_leader in out -def test_update_database_with_default_leader(capsys, multi_region_instance, multi_region_instance_id, default_leader_database_id, default_leader): +def test_update_database_with_default_leader( + capsys, + multi_region_instance, + multi_region_instance_id, + default_leader_database_id, + default_leader, +): retry_429 = RetryErrors(exceptions.ResourceExhausted, delay=15) retry_429(snippets.update_database_with_default_leader)( multi_region_instance_id, default_leader_database_id, default_leader @@ -176,7 +192,13 @@ def test_get_database_ddl(capsys, instance_id, sample_database): assert sample_database.database_id in out -def test_query_information_schema_database_options(capsys, multi_region_instance, multi_region_instance_id, default_leader_database_id, default_leader): +def test_query_information_schema_database_options( + capsys, + multi_region_instance, + multi_region_instance_id, + default_leader_database_id, + default_leader, +): snippets.query_information_schema_database_options( multi_region_instance_id, default_leader_database_id ) @@ -587,7 +609,9 @@ def test_query_data_with_json_parameter(capsys, instance_id, sample_database): @pytest.mark.dependency(depends=["insert_datatypes_data"]) def test_query_data_with_timestamp_parameter(capsys, instance_id, sample_database): - snippets.query_data_with_timestamp_parameter(instance_id, sample_database.database_id) + snippets.query_data_with_timestamp_parameter( + instance_id, sample_database.database_id + ) out, _ = capsys.readouterr() assert "VenueId: 4, VenueName: Venue 4, LastUpdateTime:" in out assert "VenueId: 19, VenueName: Venue 19, LastUpdateTime:" in out diff --git a/scripts/fixup_spanner_admin_database_v1_keywords.py b/scripts/fixup_spanner_admin_database_v1_keywords.py index 9ac9f80702..af7791c4ad 100644 --- a/scripts/fixup_spanner_admin_database_v1_keywords.py +++ b/scripts/fixup_spanner_admin_database_v1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ def partition( class spanner_admin_databaseCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'copy_backup': ('parent', 'backup_id', 'source_backup', 'expire_time', 'encryption_config', ), 'create_backup': ('parent', 'backup_id', 'backup', 'encryption_config', ), 'create_database': ('parent', 'create_statement', 'extra_statements', 'encryption_config', 'database_dialect', ), 'delete_backup': ('name', ), @@ -52,7 +53,7 @@ class spanner_admin_databaseCallTransformer(cst.CSTTransformer): 'list_database_operations': ('parent', 'filter', 'page_size', 'page_token', ), 'list_databases': ('parent', 'page_size', 'page_token', ), 'restore_database': ('parent', 'database_id', 'backup', 'encryption_config', ), - 'set_iam_policy': ('resource', 'policy', ), + 'set_iam_policy': ('resource', 'policy', 'update_mask', ), 'test_iam_permissions': ('resource', 'permissions', ), 'update_backup': ('backup', 'update_mask', ), 'update_database_ddl': ('database', 'statements', 'operation_id', ), diff --git a/scripts/fixup_spanner_admin_instance_v1_keywords.py b/scripts/fixup_spanner_admin_instance_v1_keywords.py index afbc7517bc..7b8b1c9895 100644 --- a/scripts/fixup_spanner_admin_instance_v1_keywords.py +++ b/scripts/fixup_spanner_admin_instance_v1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ class spanner_admin_instanceCallTransformer(cst.CSTTransformer): 'get_instance_config': ('name', ), 'list_instance_configs': ('parent', 'page_size', 'page_token', ), 'list_instances': ('parent', 'page_size', 'page_token', 'filter', ), - 'set_iam_policy': ('resource', 'policy', ), + 'set_iam_policy': ('resource', 'policy', 'update_mask', ), 'test_iam_permissions': ('resource', 'permissions', ), 'update_instance': ('instance', 'field_mask', ), } diff --git a/scripts/fixup_spanner_v1_keywords.py b/scripts/fixup_spanner_v1_keywords.py index fec728843e..ed532c0d8f 100644 --- a/scripts/fixup_spanner_v1_keywords.py +++ b/scripts/fixup_spanner_v1_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index 39649d6e28..28fd020ab5 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-spanner" description = "Cloud Spanner API client library" -version = "3.13.0" +version = "3.14.0" # Should be one of: # 'Development Status :: 3 - Alpha' # 'Development Status :: 4 - Beta' @@ -32,13 +32,13 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", # NOTE: Maintainers, please do not require google-cloud-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 "google-cloud-core >= 1.4.1, < 3.0dev", - "grpc-google-iam-v1 >= 0.12.3, < 0.13dev", - "proto-plus >= 1.11.0, != 1.19.6", + "grpc-google-iam-v1 >= 0.12.4, <1.0.0dev", + "proto-plus >= 1.15.0, != 1.19.6", "sqlparse >= 0.3.0", "packaging >= 14.3", ] diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 2eac9c8653..4c581a9373 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,11 +5,11 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.31.5 google-cloud-core==1.4.1 -grpc-google-iam-v1==0.12.3 +grpc-google-iam-v1==0.12.4 libcst==0.2.5 -proto-plus==1.13.0 +proto-plus==1.15.0 sqlparse==0.3.0 opentelemetry-api==1.1.0 opentelemetry-sdk==1.1.0 diff --git a/tests/__init__.py b/tests/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/system/_helpers.py b/tests/system/_helpers.py index 2d0df01718..80eb9361cd 100644 --- a/tests/system/_helpers.py +++ b/tests/system/_helpers.py @@ -39,6 +39,9 @@ DATABASE_OPERATION_TIMEOUT_IN_SECONDS = int( os.getenv("SPANNER_DATABASE_OPERATION_TIMEOUT_IN_SECONDS", 120) ) +BACKUP_OPERATION_TIMEOUT_IN_SECONDS = int( + os.getenv("SPANNER_BACKUP_OPERATION_TIMEOUT_IN_SECONDS", 1200) +) USE_EMULATOR_ENVVAR = "SPANNER_EMULATOR_HOST" USE_EMULATOR = os.getenv(USE_EMULATOR_ENVVAR) is not None diff --git a/tests/system/_sample_data.py b/tests/system/_sample_data.py index 65f6e23ad3..a7f3b80a86 100644 --- a/tests/system/_sample_data.py +++ b/tests/system/_sample_data.py @@ -23,9 +23,9 @@ TABLE = "contacts" COLUMNS = ("contact_id", "first_name", "last_name", "email") ROW_DATA = ( - (1, u"Phred", u"Phlyntstone", u"phred@example.com"), - (2, u"Bharney", u"Rhubble", u"bharney@example.com"), - (3, u"Wylma", u"Phlyntstone", u"wylma@example.com"), + (1, "Phred", "Phlyntstone", "phred@example.com"), + (2, "Bharney", "Rhubble", "bharney@example.com"), + (3, "Wylma", "Phlyntstone", "wylma@example.com"), ) ALL = spanner_v1.KeySet(all_=True) SQL = "SELECT * FROM contacts ORDER BY contact_id" diff --git a/tests/system/conftest.py b/tests/system/conftest.py index 7e74725189..0568b3bf3f 100644 --- a/tests/system/conftest.py +++ b/tests/system/conftest.py @@ -12,12 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import datetime import time import pytest from google.cloud import spanner_v1 from . import _helpers +from google.cloud.spanner_admin_database_v1.types.backup import ( + CreateBackupEncryptionConfig, +) @pytest.fixture(scope="function") @@ -51,7 +55,8 @@ def spanner_client(): credentials = AnonymousCredentials() return spanner_v1.Client( - project=_helpers.EMULATOR_PROJECT, credentials=credentials, + project=_helpers.EMULATOR_PROJECT, + credentials=credentials, ) else: return spanner_v1.Client() # use google.auth.default credentials @@ -67,6 +72,11 @@ def database_operation_timeout(): return _helpers.DATABASE_OPERATION_TIMEOUT_IN_SECONDS +@pytest.fixture(scope="session") +def backup_operation_timeout(): + return _helpers.BACKUP_OPERATION_TIMEOUT_IN_SECONDS + + @pytest.fixture(scope="session") def shared_instance_id(): if _helpers.CREATE_INSTANCE: @@ -152,6 +162,30 @@ def shared_database(shared_instance, database_operation_timeout): database.drop() +@pytest.fixture(scope="session") +def shared_backup(shared_instance, shared_database, backup_operation_timeout): + backup_name = _helpers.unique_id("test_backup") + expire_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta( + days=3 + ) + source_encryption_enum = CreateBackupEncryptionConfig.EncryptionType + source_encryption_config = CreateBackupEncryptionConfig( + encryption_type=source_encryption_enum.GOOGLE_DEFAULT_ENCRYPTION, + ) + backup = shared_instance.backup( + backup_name, + database=shared_database, + expire_time=expire_time, + encryption_config=source_encryption_config, + ) + operation = backup.create() + operation.result(backup_operation_timeout) # raises on failure / timeout. + + yield backup + + backup.delete() + + @pytest.fixture(scope="function") def databases_to_delete(): to_delete = [] diff --git a/tests/system/test_backup_api.py b/tests/system/test_backup_api.py index 77ffca0f44..c09c06a5f2 100644 --- a/tests/system/test_backup_api.py +++ b/tests/system/test_backup_api.py @@ -60,7 +60,10 @@ def diff_config(shared_instance, instance_configs): @pytest.fixture(scope="session") def diff_config_instance( - spanner_client, shared_instance, instance_operation_timeout, diff_config, + spanner_client, + shared_instance, + instance_operation_timeout, + diff_config, ): if diff_config is None: return None @@ -180,7 +183,8 @@ def test_backup_workflow( encryption_type=RestoreDatabaseEncryptionConfig.EncryptionType.GOOGLE_DEFAULT_ENCRYPTION, ) database = shared_instance.database( - restored_id, encryption_config=encryption_config, + restored_id, + encryption_config=encryption_config, ) databases_to_delete.append(database) operation = database.restore(source=backup) @@ -199,8 +203,69 @@ def test_backup_workflow( assert not backup.exists() +def test_copy_backup_workflow( + shared_instance, + shared_backup, + backups_to_delete, +): + from google.cloud.spanner_admin_database_v1 import ( + CopyBackupEncryptionConfig, + EncryptionInfo, + ) + + backup_id = _helpers.unique_id("backup_id", separator="_") + expire_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta( + days=3 + ) + copy_encryption_enum = CopyBackupEncryptionConfig.EncryptionType + copy_encryption_config = CopyBackupEncryptionConfig( + encryption_type=copy_encryption_enum.GOOGLE_DEFAULT_ENCRYPTION, + ) + + # Create backup. + shared_backup.reload() + # Create a copy backup + copy_backup = shared_instance.copy_backup( + backup_id=backup_id, + source_backup=shared_backup.name, + expire_time=expire_time, + encryption_config=copy_encryption_config, + ) + operation = copy_backup.create() + backups_to_delete.append(copy_backup) + + # Check metadata. + metadata = operation.metadata + assert copy_backup.name == metadata.name + operation.result() # blocks indefinitely + + # Check backup object. + copy_backup.reload() + assert expire_time == copy_backup.expire_time + assert copy_backup.create_time is not None + assert copy_backup.size_bytes is not None + assert copy_backup.state is not None + assert ( + EncryptionInfo.Type.GOOGLE_DEFAULT_ENCRYPTION + == copy_backup.encryption_info.encryption_type + ) + + # Update with valid argument. + valid_expire_time = datetime.datetime.now( + datetime.timezone.utc + ) + datetime.timedelta(days=7) + copy_backup.update_expire_time(valid_expire_time) + assert valid_expire_time == copy_backup.expire_time + + copy_backup.delete() + assert not copy_backup.exists() + + def test_backup_create_w_version_time_dflt_to_create_time( - shared_instance, shared_database, backups_to_delete, databases_to_delete, + shared_instance, + shared_database, + backups_to_delete, + databases_to_delete, ): backup_id = _helpers.unique_id("backup_id", separator="_") expire_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta( @@ -209,7 +274,9 @@ def test_backup_create_w_version_time_dflt_to_create_time( # Create backup. backup = shared_instance.backup( - backup_id, database=shared_database, expire_time=expire_time, + backup_id, + database=shared_database, + expire_time=expire_time, ) operation = backup.create() backups_to_delete.append(backup) @@ -244,7 +311,8 @@ def test_backup_create_w_invalid_expire_time(shared_instance, shared_database): def test_backup_create_w_invalid_version_time_past( - shared_instance, shared_database, + shared_instance, + shared_database, ): backup_id = _helpers.unique_id("backup_id", separator="_") expire_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta( @@ -267,7 +335,8 @@ def test_backup_create_w_invalid_version_time_past( def test_backup_create_w_invalid_version_time_future( - shared_instance, shared_database, + shared_instance, + shared_database, ): backup_id = _helpers.unique_id("backup_id", separator="_") expire_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta( @@ -303,7 +372,9 @@ def test_database_restore_to_diff_instance( # Create backup. backup = shared_instance.backup( - backup_id, database=shared_database, expire_time=expire_time, + backup_id, + database=shared_database, + expire_time=expire_time, ) op = backup.create() backups_to_delete.append(backup) @@ -383,7 +454,10 @@ def test_multi_create_cancel_update_error_restore_errors( def test_instance_list_backups( - shared_instance, shared_database, second_database, backups_to_delete, + shared_instance, + shared_database, + second_database, + backups_to_delete, ): # Remove un-scrubbed backups FBO count below. _helpers.scrub_instance_backups(shared_instance) @@ -397,7 +471,9 @@ def test_instance_list_backups( expire_time_1_stamp = expire_time_1.strftime("%Y-%m-%dT%H:%M:%S.%fZ") backup1 = shared_instance.backup( - backup_id_1, database=shared_database, expire_time=expire_time_1, + backup_id_1, + database=shared_database, + expire_time=expire_time_1, ) expire_time_2 = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta( diff --git a/tests/system/test_database_api.py b/tests/system/test_database_api.py index d702748a53..09f6d0e038 100644 --- a/tests/system/test_database_api.py +++ b/tests/system/test_database_api.py @@ -207,7 +207,9 @@ def test_update_ddl_w_operation_id(shared_instance, databases_to_delete): def test_update_ddl_w_pitr_invalid( - not_emulator, shared_instance, databases_to_delete, + not_emulator, + shared_instance, + databases_to_delete, ): pool = spanner_v1.BurstyPool(labels={"testcase": "update_database_ddl_pitr"}) temp_db_id = _helpers.unique_id("pitr_upd_ddl_inv", separator="_") @@ -229,7 +231,9 @@ def test_update_ddl_w_pitr_invalid( def test_update_ddl_w_pitr_success( - not_emulator, shared_instance, databases_to_delete, + not_emulator, + shared_instance, + databases_to_delete, ): pool = spanner_v1.BurstyPool(labels={"testcase": "update_database_ddl_pitr"}) temp_db_id = _helpers.unique_id("pitr_upd_ddl_inv", separator="_") @@ -255,7 +259,9 @@ def test_update_ddl_w_pitr_success( def test_update_ddl_w_default_leader_success( - not_emulator, multiregion_instance, databases_to_delete, + not_emulator, + multiregion_instance, + databases_to_delete, ): pool = spanner_v1.BurstyPool( labels={"testcase": "update_database_ddl_default_leader"}, diff --git a/tests/system/test_dbapi.py b/tests/system/test_dbapi.py index 49efc7e3f4..9557a46b37 100644 --- a/tests/system/test_dbapi.py +++ b/tests/system/test_dbapi.py @@ -45,7 +45,9 @@ def raw_database(shared_instance, database_operation_timeout): databse_id = _helpers.unique_id("dbapi-txn") pool = spanner_v1.BurstyPool(labels={"testcase": "database_api"}) database = shared_instance.database( - databse_id, ddl_statements=DDL_STATEMENTS, pool=pool, + databse_id, + ddl_statements=DDL_STATEMENTS, + pool=pool, ) op = database.create() op.result(database_operation_timeout) # raises on failure / timeout. @@ -285,7 +287,8 @@ def test_execute_many(shared_instance, dbapi_database): conn.commit() cursor.executemany( - """SELECT * FROM contacts WHERE contact_id = %s""", ((1,), (2,)), + """SELECT * FROM contacts WHERE contact_id = %s""", + ((1,), (2,)), ) res = cursor.fetchall() conn.commit() diff --git a/tests/system/test_instance_api.py b/tests/system/test_instance_api.py index 8992174871..6825e50721 100644 --- a/tests/system/test_instance_api.py +++ b/tests/system/test_instance_api.py @@ -30,7 +30,10 @@ def instances_to_delete(): def test_list_instances( - no_create_instance, spanner_client, existing_instances, shared_instance, + no_create_instance, + spanner_client, + existing_instances, + shared_instance, ): instances = list(spanner_client.list_instances()) diff --git a/tests/system/test_session_api.py b/tests/system/test_session_api.py index 3fc523e46b..09c65970f3 100644 --- a/tests/system/test_session_api.py +++ b/tests/system/test_session_api.py @@ -53,7 +53,9 @@ "sample_array": [23, 76, 19], } ) -JSON_2 = JsonObject({"sample_object": {"name": "Anamika", "id": 2635}},) +JSON_2 = JsonObject( + {"sample_object": {"name": "Anamika", "id": 2635}}, +) COUNTERS_TABLE = "counters" COUNTERS_COLUMNS = ("name", "value") @@ -167,7 +169,9 @@ def sessions_database(shared_instance, database_operation_timeout): database_name = _helpers.unique_id("test_sessions", separator="_") pool = spanner_v1.BurstyPool(labels={"testcase": "session_api"}) sessions_database = shared_instance.database( - database_name, ddl_statements=_helpers.DDL_STATEMENTS, pool=pool, + database_name, + ddl_statements=_helpers.DDL_STATEMENTS, + pool=pool, ) operation = sessions_database.create() operation.result(database_operation_timeout) # raises on failure / timeout. @@ -426,7 +430,9 @@ def test_batch_insert_w_commit_timestamp(sessions_database): @_helpers.retry_mabye_aborted_txn def test_transaction_read_and_insert_then_rollback( - sessions_database, ot_exporter, sessions_to_delete, + sessions_database, + ot_exporter, + sessions_to_delete, ): sd = _sample_data db_name = sessions_database.name @@ -486,7 +492,9 @@ def test_transaction_read_and_insert_then_rollback( ot_exporter, "CloudSpanner.ReadOnlyTransaction", attributes=_make_attributes( - db_name, table_id=sd.TABLE, columns=sd.COLUMNS, + db_name, + table_id=sd.TABLE, + columns=sd.COLUMNS, ), span=span_list[4], ) @@ -494,7 +502,9 @@ def test_transaction_read_and_insert_then_rollback( ot_exporter, "CloudSpanner.ReadOnlyTransaction", attributes=_make_attributes( - db_name, table_id=sd.TABLE, columns=sd.COLUMNS, + db_name, + table_id=sd.TABLE, + columns=sd.COLUMNS, ), span=span_list[5], ) @@ -508,7 +518,9 @@ def test_transaction_read_and_insert_then_rollback( ot_exporter, "CloudSpanner.ReadOnlyTransaction", attributes=_make_attributes( - db_name, table_id=sd.TABLE, columns=sd.COLUMNS, + db_name, + table_id=sd.TABLE, + columns=sd.COLUMNS, ), span=span_list[7], ) @@ -543,7 +555,8 @@ def _transaction_read_then_raise(transaction): @_helpers.retry_mabye_conflict def test_transaction_read_and_insert_or_update_then_commit( - sessions_database, sessions_to_delete, + sessions_database, + sessions_to_delete, ): # [START spanner_test_dml_read_your_writes] sd = _sample_data @@ -581,7 +594,8 @@ def _generate_insert_statements(): @_helpers.retry_mabye_conflict def test_transaction_execute_sql_w_dml_read_rollback( - sessions_database, sessions_to_delete, + sessions_database, + sessions_to_delete, ): # [START spanner_test_dml_rollback_txn_not_committed] sd = _sample_data @@ -723,7 +737,8 @@ def unit_of_work(transaction): def test_transaction_batch_update_and_execute_dml( - sessions_database, sessions_to_delete, + sessions_database, + sessions_to_delete, ): sd = _sample_data param_types = spanner_v1.param_types @@ -819,10 +834,13 @@ def test_transaction_batch_update_wo_statements(sessions_database, sessions_to_d @pytest.mark.skipif( - not ot_helpers.HAS_OPENTELEMETRY_INSTALLED, reason="trace requires OpenTelemetry", + not ot_helpers.HAS_OPENTELEMETRY_INSTALLED, + reason="trace requires OpenTelemetry", ) def test_transaction_batch_update_w_parent_span( - sessions_database, sessions_to_delete, ot_exporter, + sessions_database, + sessions_to_delete, + ot_exporter, ): from opentelemetry import trace @@ -1093,7 +1111,10 @@ def test_read_with_multiple_keys_index(sessions_database): with sessions_database.snapshot() as snapshot: rows = list( snapshot.read( - sd.TABLE, columns, spanner_v1.KeySet(keys=expected), index="name", + sd.TABLE, + columns, + spanner_v1.KeySet(keys=expected), + index="name", ) ) assert rows == expected @@ -1291,7 +1312,8 @@ def test_read_w_ranges(sessions_database): end = 2000 committed = _set_up_table(sessions_database, row_count) with sessions_database.snapshot( - read_timestamp=committed, multi_use=True, + read_timestamp=committed, + multi_use=True, ) as snapshot: all_data_rows = list(_row_data(row_count)) @@ -1332,7 +1354,8 @@ def test_read_partial_range_until_end(sessions_database): start = 1000 committed = _set_up_table(sessions_database, row_count) with sessions_database.snapshot( - read_timestamp=committed, multi_use=True, + read_timestamp=committed, + multi_use=True, ) as snapshot: all_data_rows = list(_row_data(row_count)) @@ -1376,7 +1399,8 @@ def test_read_partial_range_from_beginning(sessions_database): keyset = spanner_v1.KeySet(ranges=(spanner_v1.KeyRange(**range_kwargs),)) with sessions_database.snapshot( - read_timestamp=committed, multi_use=True, + read_timestamp=committed, + multi_use=True, ) as snapshot: rows = list(snapshot.read(sd.TABLE, sd.COLUMNS, keyset)) expected = expected_map[(start_arg, end_arg)] @@ -1623,7 +1647,13 @@ def test_execute_sql_w_manual_consume(sessions_database): def _check_sql_results( - database, sql, params, param_types, expected, order=True, recurse_into_lists=True, + database, + sql, + params, + param_types, + expected, + order=True, + recurse_into_lists=True, ): if order and "ORDER" not in sql: sql += " ORDER BY pkey" @@ -1886,7 +1916,10 @@ def test_execute_sql_w_numeric_bindings(not_emulator, sessions_database): def test_execute_sql_w_json_bindings(not_emulator, sessions_database): _bind_test_helper( - sessions_database, spanner_v1.TypeCode.JSON, JSON_1, [JSON_1, JSON_2], + sessions_database, + spanner_v1.TypeCode.JSON, + JSON_1, + [JSON_1, JSON_2], ) diff --git a/tests/system/utils/streaming_utils.py b/tests/system/utils/streaming_utils.py index a39637bf0f..174ddae557 100644 --- a/tests/system/utils/streaming_utils.py +++ b/tests/system/utils/streaming_utils.py @@ -26,7 +26,7 @@ class _TableDesc( ) ): def value(self): - return u"X" * self.value_size + return "X" * self.value_size FOUR_KAY = _TableDesc("four_kay", 1000, 4096, 1) diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/spanner_admin_database_v1/__init__.py b/tests/unit/gapic/spanner_admin_database_v1/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/spanner_admin_database_v1/__init__.py +++ b/tests/unit/gapic/spanner_admin_database_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py b/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py index bf80690516..bf1a442f66 100644 --- a/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py +++ b/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -106,20 +106,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [DatabaseAdminClient, DatabaseAdminAsyncClient,] + "client_class,transport_name", + [ + (DatabaseAdminClient, "grpc"), + (DatabaseAdminAsyncClient, "grpc_asyncio"), + ], ) -def test_database_admin_client_from_service_account_info(client_class): +def test_database_admin_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") @pytest.mark.parametrize( @@ -148,23 +152,31 @@ def test_database_admin_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", [DatabaseAdminClient, DatabaseAdminAsyncClient,] + "client_class,transport_name", + [ + (DatabaseAdminClient, "grpc"), + (DatabaseAdminAsyncClient, "grpc_asyncio"), + ], ) -def test_database_admin_client_from_service_account_file(client_class): +def test_database_admin_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") def test_database_admin_client_get_transport_class(): @@ -512,7 +524,9 @@ def test_database_admin_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -656,11 +670,16 @@ def test_database_admin_client_create_channel_credentials_file( @pytest.mark.parametrize( - "request_type", [spanner_database_admin.ListDatabasesRequest, dict,] + "request_type", + [ + spanner_database_admin.ListDatabasesRequest, + dict, + ], ) def test_list_databases(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -689,7 +708,8 @@ def test_list_databases_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -706,7 +726,8 @@ async def test_list_databases_async( request_type=spanner_database_admin.ListDatabasesRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -739,7 +760,9 @@ async def test_list_databases_async_from_dict(): def test_list_databases_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -759,7 +782,10 @@ def test_list_databases_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -788,11 +814,16 @@ async def test_list_databases_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_list_databases_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_databases), "__call__") as call: @@ -800,7 +831,9 @@ def test_list_databases_flattened(): call.return_value = spanner_database_admin.ListDatabasesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_databases(parent="parent_value",) + client.list_databases( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -812,13 +845,16 @@ def test_list_databases_flattened(): def test_list_databases_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_databases( - spanner_database_admin.ListDatabasesRequest(), parent="parent_value", + spanner_database_admin.ListDatabasesRequest(), + parent="parent_value", ) @@ -838,7 +874,9 @@ async def test_list_databases_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_databases(parent="parent_value",) + response = await client.list_databases( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -859,13 +897,15 @@ async def test_list_databases_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_databases( - spanner_database_admin.ListDatabasesRequest(), parent="parent_value", + spanner_database_admin.ListDatabasesRequest(), + parent="parent_value", ) def test_list_databases_pager(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -881,10 +921,14 @@ def test_list_databases_pager(transport_name: str = "grpc"): next_page_token="abc", ), spanner_database_admin.ListDatabasesResponse( - databases=[], next_page_token="def", + databases=[], + next_page_token="def", ), spanner_database_admin.ListDatabasesResponse( - databases=[spanner_database_admin.Database(),], next_page_token="ghi", + databases=[ + spanner_database_admin.Database(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabasesResponse( databases=[ @@ -910,7 +954,8 @@ def test_list_databases_pager(transport_name: str = "grpc"): def test_list_databases_pages(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -926,10 +971,14 @@ def test_list_databases_pages(transport_name: str = "grpc"): next_page_token="abc", ), spanner_database_admin.ListDatabasesResponse( - databases=[], next_page_token="def", + databases=[], + next_page_token="def", ), spanner_database_admin.ListDatabasesResponse( - databases=[spanner_database_admin.Database(),], next_page_token="ghi", + databases=[ + spanner_database_admin.Database(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabasesResponse( databases=[ @@ -946,7 +995,9 @@ def test_list_databases_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_databases_async_pager(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -963,10 +1014,14 @@ async def test_list_databases_async_pager(): next_page_token="abc", ), spanner_database_admin.ListDatabasesResponse( - databases=[], next_page_token="def", + databases=[], + next_page_token="def", ), spanner_database_admin.ListDatabasesResponse( - databases=[spanner_database_admin.Database(),], next_page_token="ghi", + databases=[ + spanner_database_admin.Database(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabasesResponse( databases=[ @@ -976,10 +1031,12 @@ async def test_list_databases_async_pager(): ), RuntimeError, ) - async_pager = await client.list_databases(request={},) + async_pager = await client.list_databases( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -988,7 +1045,9 @@ async def test_list_databases_async_pager(): @pytest.mark.asyncio async def test_list_databases_async_pages(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1005,10 +1064,14 @@ async def test_list_databases_async_pages(): next_page_token="abc", ), spanner_database_admin.ListDatabasesResponse( - databases=[], next_page_token="def", + databases=[], + next_page_token="def", ), spanner_database_admin.ListDatabasesResponse( - databases=[spanner_database_admin.Database(),], next_page_token="ghi", + databases=[ + spanner_database_admin.Database(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabasesResponse( databases=[ @@ -1019,18 +1082,25 @@ async def test_list_databases_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_databases(request={})).pages: + async for page_ in ( + await client.list_databases(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( - "request_type", [spanner_database_admin.CreateDatabaseRequest, dict,] + "request_type", + [ + spanner_database_admin.CreateDatabaseRequest, + dict, + ], ) def test_create_database(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1056,7 +1126,8 @@ def test_create_database_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1073,7 +1144,8 @@ async def test_create_database_async( request_type=spanner_database_admin.CreateDatabaseRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1103,7 +1175,9 @@ async def test_create_database_async_from_dict(): def test_create_database_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -1123,7 +1197,10 @@ def test_create_database_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1152,11 +1229,16 @@ async def test_create_database_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_create_database_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_database), "__call__") as call: @@ -1165,7 +1247,8 @@ def test_create_database_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_database( - parent="parent_value", create_statement="create_statement_value", + parent="parent_value", + create_statement="create_statement_value", ) # Establish that the underlying call was made with the expected @@ -1181,7 +1264,9 @@ def test_create_database_flattened(): def test_create_database_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1210,7 +1295,8 @@ async def test_create_database_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_database( - parent="parent_value", create_statement="create_statement_value", + parent="parent_value", + create_statement="create_statement_value", ) # Establish that the underlying call was made with the expected @@ -1242,11 +1328,16 @@ async def test_create_database_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [spanner_database_admin.GetDatabaseRequest, dict,] + "request_type", + [ + spanner_database_admin.GetDatabaseRequest, + dict, + ], ) def test_get_database(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1283,7 +1374,8 @@ def test_get_database_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1300,7 +1392,8 @@ async def test_get_database_async( request_type=spanner_database_admin.GetDatabaseRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1341,7 +1434,9 @@ async def test_get_database_async_from_dict(): def test_get_database_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -1361,7 +1456,10 @@ def test_get_database_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1390,11 +1488,16 @@ async def test_get_database_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_get_database_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_database), "__call__") as call: @@ -1402,7 +1505,9 @@ def test_get_database_flattened(): call.return_value = spanner_database_admin.Database() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_database(name="name_value",) + client.get_database( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1414,13 +1519,16 @@ def test_get_database_flattened(): def test_get_database_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_database( - spanner_database_admin.GetDatabaseRequest(), name="name_value", + spanner_database_admin.GetDatabaseRequest(), + name="name_value", ) @@ -1440,7 +1548,9 @@ async def test_get_database_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_database(name="name_value",) + response = await client.get_database( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1461,16 +1571,22 @@ async def test_get_database_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_database( - spanner_database_admin.GetDatabaseRequest(), name="name_value", + spanner_database_admin.GetDatabaseRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [spanner_database_admin.UpdateDatabaseDdlRequest, dict,] + "request_type", + [ + spanner_database_admin.UpdateDatabaseDdlRequest, + dict, + ], ) def test_update_database_ddl(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1498,7 +1614,8 @@ def test_update_database_ddl_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1517,7 +1634,8 @@ async def test_update_database_ddl_async( request_type=spanner_database_admin.UpdateDatabaseDdlRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1549,7 +1667,9 @@ async def test_update_database_ddl_async_from_dict(): def test_update_database_ddl_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -1571,7 +1691,10 @@ def test_update_database_ddl_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1602,11 +1725,16 @@ async def test_update_database_ddl_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] def test_update_database_ddl_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1617,7 +1745,8 @@ def test_update_database_ddl_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_database_ddl( - database="database_value", statements=["statements_value"], + database="database_value", + statements=["statements_value"], ) # Establish that the underlying call was made with the expected @@ -1633,7 +1762,9 @@ def test_update_database_ddl_flattened(): def test_update_database_ddl_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1664,7 +1795,8 @@ async def test_update_database_ddl_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.update_database_ddl( - database="database_value", statements=["statements_value"], + database="database_value", + statements=["statements_value"], ) # Establish that the underlying call was made with the expected @@ -1696,11 +1828,16 @@ async def test_update_database_ddl_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [spanner_database_admin.DropDatabaseRequest, dict,] + "request_type", + [ + spanner_database_admin.DropDatabaseRequest, + dict, + ], ) def test_drop_database(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1726,7 +1863,8 @@ def test_drop_database_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1743,7 +1881,8 @@ async def test_drop_database_async( request_type=spanner_database_admin.DropDatabaseRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1771,7 +1910,9 @@ async def test_drop_database_async_from_dict(): def test_drop_database_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -1791,7 +1932,10 @@ def test_drop_database_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1818,11 +1962,16 @@ async def test_drop_database_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] def test_drop_database_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.drop_database), "__call__") as call: @@ -1830,7 +1979,9 @@ def test_drop_database_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.drop_database(database="database_value",) + client.drop_database( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1842,13 +1993,16 @@ def test_drop_database_flattened(): def test_drop_database_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.drop_database( - spanner_database_admin.DropDatabaseRequest(), database="database_value", + spanner_database_admin.DropDatabaseRequest(), + database="database_value", ) @@ -1866,7 +2020,9 @@ async def test_drop_database_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.drop_database(database="database_value",) + response = await client.drop_database( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1887,16 +2043,22 @@ async def test_drop_database_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.drop_database( - spanner_database_admin.DropDatabaseRequest(), database="database_value", + spanner_database_admin.DropDatabaseRequest(), + database="database_value", ) @pytest.mark.parametrize( - "request_type", [spanner_database_admin.GetDatabaseDdlRequest, dict,] + "request_type", + [ + spanner_database_admin.GetDatabaseDdlRequest, + dict, + ], ) def test_get_database_ddl(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1925,7 +2087,8 @@ def test_get_database_ddl_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1942,7 +2105,8 @@ async def test_get_database_ddl_async( request_type=spanner_database_admin.GetDatabaseDdlRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1975,7 +2139,9 @@ async def test_get_database_ddl_async_from_dict(): def test_get_database_ddl_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -1995,7 +2161,10 @@ def test_get_database_ddl_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2024,11 +2193,16 @@ async def test_get_database_ddl_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] def test_get_database_ddl_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_database_ddl), "__call__") as call: @@ -2036,7 +2210,9 @@ def test_get_database_ddl_flattened(): call.return_value = spanner_database_admin.GetDatabaseDdlResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_database_ddl(database="database_value",) + client.get_database_ddl( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2048,13 +2224,16 @@ def test_get_database_ddl_flattened(): def test_get_database_ddl_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_database_ddl( - spanner_database_admin.GetDatabaseDdlRequest(), database="database_value", + spanner_database_admin.GetDatabaseDdlRequest(), + database="database_value", ) @@ -2074,7 +2253,9 @@ async def test_get_database_ddl_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_database_ddl(database="database_value",) + response = await client.get_database_ddl( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2095,14 +2276,22 @@ async def test_get_database_ddl_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_database_ddl( - spanner_database_admin.GetDatabaseDdlRequest(), database="database_value", + spanner_database_admin.GetDatabaseDdlRequest(), + database="database_value", ) -@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + iam_policy_pb2.SetIamPolicyRequest, + dict, + ], +) def test_set_iam_policy(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2112,7 +2301,10 @@ def test_set_iam_policy(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) response = client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2130,7 +2322,8 @@ def test_set_iam_policy_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2146,7 +2339,8 @@ async def test_set_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2157,7 +2351,10 @@ async def test_set_iam_policy_async( with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy_pb2.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) ) response = await client.set_iam_policy(request) @@ -2178,7 +2375,9 @@ async def test_set_iam_policy_async_from_dict(): def test_set_iam_policy_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -2198,7 +2397,10 @@ def test_set_iam_policy_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2225,11 +2427,16 @@ async def test_set_iam_policy_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] def test_set_iam_policy_from_dict_foreign(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. @@ -2238,13 +2445,16 @@ def test_set_iam_policy_from_dict_foreign(): request={ "resource": "resource_value", "policy": policy_pb2.Policy(version=774), + "update_mask": field_mask_pb2.FieldMask(paths=["paths_value"]), } ) call.assert_called() def test_set_iam_policy_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -2252,7 +2462,9 @@ def test_set_iam_policy_flattened(): call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.set_iam_policy(resource="resource_value",) + client.set_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2264,13 +2476,16 @@ def test_set_iam_policy_flattened(): def test_set_iam_policy_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) @@ -2288,7 +2503,9 @@ async def test_set_iam_policy_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.set_iam_policy(resource="resource_value",) + response = await client.set_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2309,14 +2526,22 @@ async def test_set_iam_policy_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) -@pytest.mark.parametrize("request_type", [iam_policy_pb2.GetIamPolicyRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + iam_policy_pb2.GetIamPolicyRequest, + dict, + ], +) def test_get_iam_policy(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2326,7 +2551,10 @@ def test_get_iam_policy(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) response = client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2344,7 +2572,8 @@ def test_get_iam_policy_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2360,7 +2589,8 @@ async def test_get_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2371,7 +2601,10 @@ async def test_get_iam_policy_async( with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy_pb2.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) ) response = await client.get_iam_policy(request) @@ -2392,7 +2625,9 @@ async def test_get_iam_policy_async_from_dict(): def test_get_iam_policy_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -2412,7 +2647,10 @@ def test_get_iam_policy_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2439,11 +2677,16 @@ async def test_get_iam_policy_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] def test_get_iam_policy_from_dict_foreign(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. @@ -2458,7 +2701,9 @@ def test_get_iam_policy_from_dict_foreign(): def test_get_iam_policy_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -2466,7 +2711,9 @@ def test_get_iam_policy_flattened(): call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_iam_policy(resource="resource_value",) + client.get_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2478,13 +2725,16 @@ def test_get_iam_policy_flattened(): def test_get_iam_policy_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.GetIamPolicyRequest(), + resource="resource_value", ) @@ -2502,7 +2752,9 @@ async def test_get_iam_policy_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_iam_policy(resource="resource_value",) + response = await client.get_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2523,16 +2775,22 @@ async def test_get_iam_policy_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.GetIamPolicyRequest(), + resource="resource_value", ) @pytest.mark.parametrize( - "request_type", [iam_policy_pb2.TestIamPermissionsRequest, dict,] + "request_type", + [ + iam_policy_pb2.TestIamPermissionsRequest, + dict, + ], ) def test_test_iam_permissions(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2563,7 +2821,8 @@ def test_test_iam_permissions_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2582,7 +2841,8 @@ async def test_test_iam_permissions_async( request_type=iam_policy_pb2.TestIamPermissionsRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2617,7 +2877,9 @@ async def test_test_iam_permissions_async_from_dict(): def test_test_iam_permissions_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -2639,7 +2901,10 @@ def test_test_iam_permissions_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2670,11 +2935,16 @@ async def test_test_iam_permissions_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] def test_test_iam_permissions_from_dict_foreign(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.test_iam_permissions), "__call__" @@ -2691,7 +2961,9 @@ def test_test_iam_permissions_from_dict_foreign(): def test_test_iam_permissions_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2702,7 +2974,8 @@ def test_test_iam_permissions_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.test_iam_permissions( - resource="resource_value", permissions=["permissions_value"], + resource="resource_value", + permissions=["permissions_value"], ) # Establish that the underlying call was made with the expected @@ -2718,7 +2991,9 @@ def test_test_iam_permissions_flattened(): def test_test_iam_permissions_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2749,7 +3024,8 @@ async def test_test_iam_permissions_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.test_iam_permissions( - resource="resource_value", permissions=["permissions_value"], + resource="resource_value", + permissions=["permissions_value"], ) # Establish that the underlying call was made with the expected @@ -2780,10 +3056,17 @@ async def test_test_iam_permissions_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [gsad_backup.CreateBackupRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + gsad_backup.CreateBackupRequest, + dict, + ], +) def test_create_backup(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2809,7 +3092,8 @@ def test_create_backup_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2825,7 +3109,8 @@ async def test_create_backup_async( transport: str = "grpc_asyncio", request_type=gsad_backup.CreateBackupRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2855,7 +3140,9 @@ async def test_create_backup_async_from_dict(): def test_create_backup_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -2875,7 +3162,10 @@ def test_create_backup_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2904,11 +3194,16 @@ async def test_create_backup_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_create_backup_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_backup), "__call__") as call: @@ -2938,9 +3233,11 @@ def test_create_backup_flattened(): def test_create_backup_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.create_backup( @@ -3005,10 +3302,273 @@ async def test_create_backup_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [backup.GetBackupRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + backup.CopyBackupRequest, + dict, + ], +) +def test_copy_backup(request_type, transport: str = "grpc"): + client = DatabaseAdminClient( + 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.copy_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.copy_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == backup.CopyBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_copy_backup_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 = DatabaseAdminClient( + 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.copy_backup), "__call__") as call: + client.copy_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == backup.CopyBackupRequest() + + +@pytest.mark.asyncio +async def test_copy_backup_async( + transport: str = "grpc_asyncio", request_type=backup.CopyBackupRequest +): + client = DatabaseAdminAsyncClient( + 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.copy_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.copy_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == backup.CopyBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_copy_backup_async_from_dict(): + await test_copy_backup_async(request_type=dict) + + +def test_copy_backup_field_headers(): + client = DatabaseAdminClient( + 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 = backup.CopyBackupRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.copy_backup), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.copy_backup(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", + "parent=parent/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_copy_backup_field_headers_async(): + client = DatabaseAdminAsyncClient( + 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 = backup.CopyBackupRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.copy_backup), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.copy_backup(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", + "parent=parent/value", + ) in kw["metadata"] + + +def test_copy_backup_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.copy_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.copy_backup( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].backup_id + mock_val = "backup_id_value" + assert arg == mock_val + arg = args[0].source_backup + mock_val = "source_backup_value" + assert arg == mock_val + assert TimestampRule().to_proto(args[0].expire_time) == timestamp_pb2.Timestamp( + seconds=751 + ) + + +def test_copy_backup_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.copy_backup( + backup.CopyBackupRequest(), + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +@pytest.mark.asyncio +async def test_copy_backup_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.copy_backup), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.copy_backup( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].backup_id + mock_val = "backup_id_value" + assert arg == mock_val + arg = args[0].source_backup + mock_val = "source_backup_value" + assert arg == mock_val + assert TimestampRule().to_proto(args[0].expire_time) == timestamp_pb2.Timestamp( + seconds=751 + ) + + +@pytest.mark.asyncio +async def test_copy_backup_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.copy_backup( + backup.CopyBackupRequest(), + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + backup.GetBackupRequest, + dict, + ], +) def test_get_backup(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3025,6 +3585,7 @@ def test_get_backup(request_type, transport: str = "grpc"): state=backup.Backup.State.CREATING, referencing_databases=["referencing_databases_value"], database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=["referencing_backups_value"], ) response = client.get_backup(request) @@ -3041,13 +3602,15 @@ def test_get_backup(request_type, transport: str = "grpc"): assert response.state == backup.Backup.State.CREATING assert response.referencing_databases == ["referencing_databases_value"] assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ["referencing_backups_value"] def test_get_backup_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3063,7 +3626,8 @@ async def test_get_backup_async( transport: str = "grpc_asyncio", request_type=backup.GetBackupRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3081,6 +3645,7 @@ async def test_get_backup_async( state=backup.Backup.State.CREATING, referencing_databases=["referencing_databases_value"], database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=["referencing_backups_value"], ) ) response = await client.get_backup(request) @@ -3098,6 +3663,7 @@ async def test_get_backup_async( assert response.state == backup.Backup.State.CREATING assert response.referencing_databases == ["referencing_databases_value"] assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ["referencing_backups_value"] @pytest.mark.asyncio @@ -3106,7 +3672,9 @@ async def test_get_backup_async_from_dict(): def test_get_backup_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -3126,7 +3694,10 @@ def test_get_backup_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3153,11 +3724,16 @@ async def test_get_backup_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_get_backup_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_backup), "__call__") as call: @@ -3165,7 +3741,9 @@ def test_get_backup_flattened(): call.return_value = backup.Backup() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_backup(name="name_value",) + client.get_backup( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -3177,13 +3755,16 @@ def test_get_backup_flattened(): def test_get_backup_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_backup( - backup.GetBackupRequest(), name="name_value", + backup.GetBackupRequest(), + name="name_value", ) @@ -3201,7 +3782,9 @@ async def test_get_backup_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_backup(name="name_value",) + response = await client.get_backup( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -3222,14 +3805,22 @@ async def test_get_backup_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_backup( - backup.GetBackupRequest(), name="name_value", + backup.GetBackupRequest(), + name="name_value", ) -@pytest.mark.parametrize("request_type", [gsad_backup.UpdateBackupRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + gsad_backup.UpdateBackupRequest, + dict, + ], +) def test_update_backup(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3246,6 +3837,7 @@ def test_update_backup(request_type, transport: str = "grpc"): state=gsad_backup.Backup.State.CREATING, referencing_databases=["referencing_databases_value"], database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=["referencing_backups_value"], ) response = client.update_backup(request) @@ -3262,13 +3854,15 @@ def test_update_backup(request_type, transport: str = "grpc"): assert response.state == gsad_backup.Backup.State.CREATING assert response.referencing_databases == ["referencing_databases_value"] assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ["referencing_backups_value"] def test_update_backup_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3284,7 +3878,8 @@ async def test_update_backup_async( transport: str = "grpc_asyncio", request_type=gsad_backup.UpdateBackupRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3302,6 +3897,7 @@ async def test_update_backup_async( state=gsad_backup.Backup.State.CREATING, referencing_databases=["referencing_databases_value"], database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=["referencing_backups_value"], ) ) response = await client.update_backup(request) @@ -3319,6 +3915,7 @@ async def test_update_backup_async( assert response.state == gsad_backup.Backup.State.CREATING assert response.referencing_databases == ["referencing_databases_value"] assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ["referencing_backups_value"] @pytest.mark.asyncio @@ -3327,7 +3924,9 @@ async def test_update_backup_async_from_dict(): def test_update_backup_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -3347,7 +3946,10 @@ def test_update_backup_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "backup.name=backup.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "backup.name=backup.name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3374,11 +3976,16 @@ async def test_update_backup_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "backup.name=backup.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "backup.name=backup.name/value", + ) in kw["metadata"] def test_update_backup_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_backup), "__call__") as call: @@ -3404,7 +4011,9 @@ def test_update_backup_flattened(): def test_update_backup_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3463,10 +4072,17 @@ async def test_update_backup_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [backup.DeleteBackupRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + backup.DeleteBackupRequest, + dict, + ], +) def test_delete_backup(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3492,7 +4108,8 @@ def test_delete_backup_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3508,7 +4125,8 @@ async def test_delete_backup_async( transport: str = "grpc_asyncio", request_type=backup.DeleteBackupRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3536,7 +4154,9 @@ async def test_delete_backup_async_from_dict(): def test_delete_backup_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -3556,7 +4176,10 @@ def test_delete_backup_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3583,11 +4206,16 @@ async def test_delete_backup_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_delete_backup_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_backup), "__call__") as call: @@ -3595,7 +4223,9 @@ def test_delete_backup_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_backup(name="name_value",) + client.delete_backup( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -3607,13 +4237,16 @@ def test_delete_backup_flattened(): def test_delete_backup_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_backup( - backup.DeleteBackupRequest(), name="name_value", + backup.DeleteBackupRequest(), + name="name_value", ) @@ -3631,7 +4264,9 @@ async def test_delete_backup_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_backup(name="name_value",) + response = await client.delete_backup( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -3652,14 +4287,22 @@ async def test_delete_backup_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_backup( - backup.DeleteBackupRequest(), name="name_value", + backup.DeleteBackupRequest(), + name="name_value", ) -@pytest.mark.parametrize("request_type", [backup.ListBackupsRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + backup.ListBackupsRequest, + dict, + ], +) def test_list_backups(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3688,7 +4331,8 @@ def test_list_backups_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3704,7 +4348,8 @@ async def test_list_backups_async( transport: str = "grpc_asyncio", request_type=backup.ListBackupsRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3715,7 +4360,9 @@ async def test_list_backups_async( with mock.patch.object(type(client.transport.list_backups), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - backup.ListBackupsResponse(next_page_token="next_page_token_value",) + backup.ListBackupsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_backups(request) @@ -3735,7 +4382,9 @@ async def test_list_backups_async_from_dict(): def test_list_backups_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -3755,7 +4404,10 @@ def test_list_backups_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3784,11 +4436,16 @@ async def test_list_backups_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_list_backups_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_backups), "__call__") as call: @@ -3796,7 +4453,9 @@ def test_list_backups_flattened(): call.return_value = backup.ListBackupsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_backups(parent="parent_value",) + client.list_backups( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -3808,13 +4467,16 @@ def test_list_backups_flattened(): def test_list_backups_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_backups( - backup.ListBackupsRequest(), parent="parent_value", + backup.ListBackupsRequest(), + parent="parent_value", ) @@ -3834,7 +4496,9 @@ async def test_list_backups_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_backups(parent="parent_value",) + response = await client.list_backups( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -3855,13 +4519,15 @@ async def test_list_backups_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_backups( - backup.ListBackupsRequest(), parent="parent_value", + backup.ListBackupsRequest(), + parent="parent_value", ) def test_list_backups_pager(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3869,14 +4535,29 @@ def test_list_backups_pager(transport_name: str = "grpc"): # Set the response to a series of pages. call.side_effect = ( backup.ListBackupsResponse( - backups=[backup.Backup(), backup.Backup(), backup.Backup(),], + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], next_page_token="abc", ), - backup.ListBackupsResponse(backups=[], next_page_token="def",), backup.ListBackupsResponse( - backups=[backup.Backup(),], next_page_token="ghi", + backups=[], + next_page_token="def", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token="ghi", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], ), - backup.ListBackupsResponse(backups=[backup.Backup(), backup.Backup(),],), RuntimeError, ) @@ -3895,7 +4576,8 @@ def test_list_backups_pager(transport_name: str = "grpc"): def test_list_backups_pages(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3903,14 +4585,29 @@ def test_list_backups_pages(transport_name: str = "grpc"): # Set the response to a series of pages. call.side_effect = ( backup.ListBackupsResponse( - backups=[backup.Backup(), backup.Backup(), backup.Backup(),], + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], next_page_token="abc", ), - backup.ListBackupsResponse(backups=[], next_page_token="def",), backup.ListBackupsResponse( - backups=[backup.Backup(),], next_page_token="ghi", + backups=[], + next_page_token="def", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token="ghi", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], ), - backup.ListBackupsResponse(backups=[backup.Backup(), backup.Backup(),],), RuntimeError, ) pages = list(client.list_backups(request={}).pages) @@ -3920,7 +4617,9 @@ def test_list_backups_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_backups_async_pager(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3929,20 +4628,37 @@ async def test_list_backups_async_pager(): # Set the response to a series of pages. call.side_effect = ( backup.ListBackupsResponse( - backups=[backup.Backup(), backup.Backup(), backup.Backup(),], + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], next_page_token="abc", ), - backup.ListBackupsResponse(backups=[], next_page_token="def",), backup.ListBackupsResponse( - backups=[backup.Backup(),], next_page_token="ghi", + backups=[], + next_page_token="def", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token="ghi", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], ), - backup.ListBackupsResponse(backups=[backup.Backup(), backup.Backup(),],), RuntimeError, ) - async_pager = await client.list_backups(request={},) + async_pager = await client.list_backups( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -3951,7 +4667,9 @@ async def test_list_backups_async_pager(): @pytest.mark.asyncio async def test_list_backups_async_pages(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3960,29 +4678,51 @@ async def test_list_backups_async_pages(): # Set the response to a series of pages. call.side_effect = ( backup.ListBackupsResponse( - backups=[backup.Backup(), backup.Backup(), backup.Backup(),], + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], next_page_token="abc", ), - backup.ListBackupsResponse(backups=[], next_page_token="def",), backup.ListBackupsResponse( - backups=[backup.Backup(),], next_page_token="ghi", + backups=[], + next_page_token="def", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token="ghi", + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], ), - backup.ListBackupsResponse(backups=[backup.Backup(), backup.Backup(),],), RuntimeError, ) pages = [] - async for page_ in (await client.list_backups(request={})).pages: + async for page_ in ( + await client.list_backups(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( - "request_type", [spanner_database_admin.RestoreDatabaseRequest, dict,] + "request_type", + [ + spanner_database_admin.RestoreDatabaseRequest, + dict, + ], ) def test_restore_database(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4008,7 +4748,8 @@ def test_restore_database_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4025,7 +4766,8 @@ async def test_restore_database_async( request_type=spanner_database_admin.RestoreDatabaseRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4055,7 +4797,9 @@ async def test_restore_database_async_from_dict(): def test_restore_database_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -4075,7 +4819,10 @@ def test_restore_database_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4104,11 +4851,16 @@ async def test_restore_database_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_restore_database_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.restore_database), "__call__") as call: @@ -4136,7 +4888,9 @@ def test_restore_database_flattened(): def test_restore_database_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4202,11 +4956,16 @@ async def test_restore_database_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [spanner_database_admin.ListDatabaseOperationsRequest, dict,] + "request_type", + [ + spanner_database_admin.ListDatabaseOperationsRequest, + dict, + ], ) def test_list_database_operations(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4237,7 +4996,8 @@ def test_list_database_operations_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4256,7 +5016,8 @@ async def test_list_database_operations_async( request_type=spanner_database_admin.ListDatabaseOperationsRequest, ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4291,7 +5052,9 @@ async def test_list_database_operations_async_from_dict(): def test_list_database_operations_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -4313,7 +5076,10 @@ def test_list_database_operations_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4344,11 +5110,16 @@ async def test_list_database_operations_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_list_database_operations_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4358,7 +5129,9 @@ def test_list_database_operations_flattened(): call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_database_operations(parent="parent_value",) + client.list_database_operations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -4370,7 +5143,9 @@ def test_list_database_operations_flattened(): def test_list_database_operations_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4399,7 +5174,9 @@ async def test_list_database_operations_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_database_operations(parent="parent_value",) + response = await client.list_database_operations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -4427,7 +5204,8 @@ async def test_list_database_operations_flattened_error_async(): def test_list_database_operations_pager(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4445,13 +5223,20 @@ def test_list_database_operations_pager(transport_name: str = "grpc"): next_page_token="abc", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], next_page_token="def", + operations=[], + next_page_token="def", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) @@ -4471,7 +5256,8 @@ def test_list_database_operations_pager(transport_name: str = "grpc"): def test_list_database_operations_pages(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4489,13 +5275,20 @@ def test_list_database_operations_pages(transport_name: str = "grpc"): next_page_token="abc", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], next_page_token="def", + operations=[], + next_page_token="def", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) @@ -4506,7 +5299,9 @@ def test_list_database_operations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_database_operations_async_pager(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4525,20 +5320,29 @@ async def test_list_database_operations_async_pager(): next_page_token="abc", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], next_page_token="def", + operations=[], + next_page_token="def", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) - async_pager = await client.list_database_operations(request={},) + async_pager = await client.list_database_operations( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -4547,7 +5351,9 @@ async def test_list_database_operations_async_pager(): @pytest.mark.asyncio async def test_list_database_operations_async_pages(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4566,27 +5372,43 @@ async def test_list_database_operations_async_pages(): next_page_token="abc", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], next_page_token="def", + operations=[], + next_page_token="def", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", ), spanner_database_admin.ListDatabaseOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_database_operations(request={})).pages: + async for page_ in ( + await client.list_database_operations(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -@pytest.mark.parametrize("request_type", [backup.ListBackupOperationsRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + backup.ListBackupOperationsRequest, + dict, + ], +) def test_list_backup_operations(request_type, transport: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4617,7 +5439,8 @@ def test_list_backup_operations_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 = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4635,7 +5458,8 @@ async def test_list_backup_operations_async( transport: str = "grpc_asyncio", request_type=backup.ListBackupOperationsRequest ): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4670,7 +5494,9 @@ async def test_list_backup_operations_async_from_dict(): def test_list_backup_operations_field_headers(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + 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. @@ -4692,7 +5518,10 @@ def test_list_backup_operations_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4723,11 +5552,16 @@ async def test_list_backup_operations_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_list_backup_operations_flattened(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4737,7 +5571,9 @@ def test_list_backup_operations_flattened(): call.return_value = backup.ListBackupOperationsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_backup_operations(parent="parent_value",) + client.list_backup_operations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -4749,13 +5585,16 @@ def test_list_backup_operations_flattened(): def test_list_backup_operations_flattened_error(): - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_backup_operations( - backup.ListBackupOperationsRequest(), parent="parent_value", + backup.ListBackupOperationsRequest(), + parent="parent_value", ) @@ -4777,7 +5616,9 @@ async def test_list_backup_operations_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_backup_operations(parent="parent_value",) + response = await client.list_backup_operations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -4798,13 +5639,15 @@ async def test_list_backup_operations_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_backup_operations( - backup.ListBackupOperationsRequest(), parent="parent_value", + backup.ListBackupOperationsRequest(), + parent="parent_value", ) def test_list_backup_operations_pager(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4821,12 +5664,21 @@ def test_list_backup_operations_pager(transport_name: str = "grpc"): ], next_page_token="abc", ), - backup.ListBackupOperationsResponse(operations=[], next_page_token="def",), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[], + next_page_token="def", ), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) @@ -4846,7 +5698,8 @@ def test_list_backup_operations_pager(transport_name: str = "grpc"): def test_list_backup_operations_pages(transport_name: str = "grpc"): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4863,12 +5716,21 @@ def test_list_backup_operations_pages(transport_name: str = "grpc"): ], next_page_token="abc", ), - backup.ListBackupOperationsResponse(operations=[], next_page_token="def",), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[], + next_page_token="def", + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", ), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) @@ -4879,7 +5741,9 @@ def test_list_backup_operations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_backup_operations_async_pager(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4897,19 +5761,30 @@ async def test_list_backup_operations_async_pager(): ], next_page_token="abc", ), - backup.ListBackupOperationsResponse(operations=[], next_page_token="def",), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[], + next_page_token="def", + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", ), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) - async_pager = await client.list_backup_operations(request={},) + async_pager = await client.list_backup_operations( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -4918,7 +5793,9 @@ async def test_list_backup_operations_async_pager(): @pytest.mark.asyncio async def test_list_backup_operations_async_pages(): - client = DatabaseAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4936,17 +5813,28 @@ async def test_list_backup_operations_async_pages(): ], next_page_token="abc", ), - backup.ListBackupOperationsResponse(operations=[], next_page_token="def",), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(),], next_page_token="ghi", + operations=[], + next_page_token="def", ), backup.ListBackupOperationsResponse( - operations=[operations_pb2.Operation(), operations_pb2.Operation(),], + operations=[ + operations_pb2.Operation(), + ], + next_page_token="ghi", + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_backup_operations(request={})).pages: + async for page_ in ( + await client.list_backup_operations(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -4959,7 +5847,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -4979,7 +5868,10 @@ def test_credentials_transport_error(): options = client_options.ClientOptions() options.api_key = "api_key" with pytest.raises(ValueError): - client = DatabaseAdminClient(client_options=options, transport=transport,) + client = DatabaseAdminClient( + client_options=options, + transport=transport, + ) # It is an error to provide an api_key and a credential. options = mock.Mock() @@ -4995,7 +5887,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DatabaseAdminClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -5038,10 +5931,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = DatabaseAdminClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = DatabaseAdminClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.DatabaseAdminGrpcTransport,) + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DatabaseAdminGrpcTransport, + ) def test_database_admin_base_transport_error(): @@ -5076,6 +5987,7 @@ def test_database_admin_base_transport(): "get_iam_policy", "test_iam_permissions", "create_backup", + "copy_backup", "get_backup", "update_backup", "delete_backup", @@ -5096,6 +6008,14 @@ def test_database_admin_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_database_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -5107,7 +6027,8 @@ def test_database_admin_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatabaseAdminTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -5252,24 +6173,40 @@ def test_database_admin_grpc_transport_client_cert_source_for_mtls(transport_cla ) -def test_database_admin_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_database_admin_host_no_port(transport_name): client = DatabaseAdminClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="spanner.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") -def test_database_admin_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_database_admin_host_with_port(transport_name): client = DatabaseAdminClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="spanner.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "spanner.googleapis.com:8000" + assert client.transport._host == ("spanner.googleapis.com:8000") def test_database_admin_grpc_transport_channel(): @@ -5277,7 +6214,8 @@ def test_database_admin_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.DatabaseAdminGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -5289,7 +6227,8 @@ def test_database_admin_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.DatabaseAdminGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -5396,12 +6335,16 @@ def test_database_admin_transport_channel_mtls_with_adc(transport_class): def test_database_admin_grpc_lro_client(): client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -5409,12 +6352,16 @@ def test_database_admin_grpc_lro_client(): def test_database_admin_grpc_lro_async_client(): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -5425,7 +6372,9 @@ def test_backup_path(): instance = "clam" backup = "whelk" expected = "projects/{project}/instances/{instance}/backups/{backup}".format( - project=project, instance=instance, backup=backup, + project=project, + instance=instance, + backup=backup, ) actual = DatabaseAdminClient.backup_path(project, instance, backup) assert expected == actual @@ -5450,7 +6399,10 @@ def test_crypto_key_path(): key_ring = "winkle" crypto_key = "nautilus" expected = "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format( - project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, + project=project, + location=location, + key_ring=key_ring, + crypto_key=crypto_key, ) actual = DatabaseAdminClient.crypto_key_path( project, location, key_ring, crypto_key @@ -5511,7 +6463,9 @@ def test_database_path(): instance = "clam" database = "whelk" expected = "projects/{project}/instances/{instance}/databases/{database}".format( - project=project, instance=instance, database=database, + project=project, + instance=instance, + database=database, ) actual = DatabaseAdminClient.database_path(project, instance, database) assert expected == actual @@ -5534,7 +6488,8 @@ def test_instance_path(): project = "cuttlefish" instance = "mussel" expected = "projects/{project}/instances/{instance}".format( - project=project, instance=instance, + project=project, + instance=instance, ) actual = DatabaseAdminClient.instance_path(project, instance) assert expected == actual @@ -5574,7 +6529,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "squid" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = DatabaseAdminClient.common_folder_path(folder) assert expected == actual @@ -5592,7 +6549,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "whelk" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = DatabaseAdminClient.common_organization_path(organization) assert expected == actual @@ -5610,7 +6569,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "oyster" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = DatabaseAdminClient.common_project_path(project) assert expected == actual @@ -5630,7 +6591,8 @@ def test_common_location_path(): project = "cuttlefish" location = "mussel" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = DatabaseAdminClient.common_location_path(project, location) assert expected == actual @@ -5655,7 +6617,8 @@ def test_client_with_default_client_info(): transports.DatabaseAdminTransport, "_prep_wrapped_messages" ) as prep: client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5664,7 +6627,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DatabaseAdminClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5672,7 +6636,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close" diff --git a/tests/unit/gapic/spanner_admin_instance_v1/__init__.py b/tests/unit/gapic/spanner_admin_instance_v1/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/spanner_admin_instance_v1/__init__.py +++ b/tests/unit/gapic/spanner_admin_instance_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py b/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py index 64fed509dd..59e7134f41 100644 --- a/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py +++ b/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -99,20 +99,24 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [InstanceAdminClient, InstanceAdminAsyncClient,] + "client_class,transport_name", + [ + (InstanceAdminClient, "grpc"), + (InstanceAdminAsyncClient, "grpc_asyncio"), + ], ) -def test_instance_admin_client_from_service_account_info(client_class): +def test_instance_admin_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") @pytest.mark.parametrize( @@ -141,23 +145,31 @@ def test_instance_admin_client_service_account_always_use_jwt( @pytest.mark.parametrize( - "client_class", [InstanceAdminClient, InstanceAdminAsyncClient,] + "client_class,transport_name", + [ + (InstanceAdminClient, "grpc"), + (InstanceAdminAsyncClient, "grpc_asyncio"), + ], ) -def test_instance_admin_client_from_service_account_file(client_class): +def test_instance_admin_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") def test_instance_admin_client_get_transport_class(): @@ -505,7 +517,9 @@ def test_instance_admin_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -649,11 +663,16 @@ def test_instance_admin_client_create_channel_credentials_file( @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.ListInstanceConfigsRequest, dict,] + "request_type", + [ + spanner_instance_admin.ListInstanceConfigsRequest, + dict, + ], ) def test_list_instance_configs(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -684,7 +703,8 @@ def test_list_instance_configs_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -703,7 +723,8 @@ async def test_list_instance_configs_async( request_type=spanner_instance_admin.ListInstanceConfigsRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -738,7 +759,9 @@ async def test_list_instance_configs_async_from_dict(): def test_list_instance_configs_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -760,7 +783,10 @@ def test_list_instance_configs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -791,11 +817,16 @@ async def test_list_instance_configs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_list_instance_configs_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -805,7 +836,9 @@ def test_list_instance_configs_flattened(): call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_instance_configs(parent="parent_value",) + client.list_instance_configs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -817,13 +850,16 @@ def test_list_instance_configs_flattened(): def test_list_instance_configs_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_instance_configs( - spanner_instance_admin.ListInstanceConfigsRequest(), parent="parent_value", + spanner_instance_admin.ListInstanceConfigsRequest(), + parent="parent_value", ) @@ -845,7 +881,9 @@ async def test_list_instance_configs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_instance_configs(parent="parent_value",) + response = await client.list_instance_configs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -866,13 +904,15 @@ async def test_list_instance_configs_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_instance_configs( - spanner_instance_admin.ListInstanceConfigsRequest(), parent="parent_value", + spanner_instance_admin.ListInstanceConfigsRequest(), + parent="parent_value", ) def test_list_instance_configs_pager(transport_name: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -890,10 +930,13 @@ def test_list_instance_configs_pager(transport_name: str = "grpc"): next_page_token="abc", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], next_page_token="def", + instance_configs=[], + next_page_token="def", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[spanner_instance_admin.InstanceConfig(),], + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], next_page_token="ghi", ), spanner_instance_admin.ListInstanceConfigsResponse( @@ -922,7 +965,8 @@ def test_list_instance_configs_pager(transport_name: str = "grpc"): def test_list_instance_configs_pages(transport_name: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,10 +984,13 @@ def test_list_instance_configs_pages(transport_name: str = "grpc"): next_page_token="abc", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], next_page_token="def", + instance_configs=[], + next_page_token="def", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[spanner_instance_admin.InstanceConfig(),], + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], next_page_token="ghi", ), spanner_instance_admin.ListInstanceConfigsResponse( @@ -961,7 +1008,9 @@ def test_list_instance_configs_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_instance_configs_async_pager(): - client = InstanceAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -980,10 +1029,13 @@ async def test_list_instance_configs_async_pager(): next_page_token="abc", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], next_page_token="def", + instance_configs=[], + next_page_token="def", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[spanner_instance_admin.InstanceConfig(),], + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], next_page_token="ghi", ), spanner_instance_admin.ListInstanceConfigsResponse( @@ -994,10 +1046,12 @@ async def test_list_instance_configs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_instance_configs(request={},) + async_pager = await client.list_instance_configs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1008,7 +1062,9 @@ async def test_list_instance_configs_async_pager(): @pytest.mark.asyncio async def test_list_instance_configs_async_pages(): - client = InstanceAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1027,10 +1083,13 @@ async def test_list_instance_configs_async_pages(): next_page_token="abc", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], next_page_token="def", + instance_configs=[], + next_page_token="def", ), spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[spanner_instance_admin.InstanceConfig(),], + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], next_page_token="ghi", ), spanner_instance_admin.ListInstanceConfigsResponse( @@ -1042,18 +1101,25 @@ async def test_list_instance_configs_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_instance_configs(request={})).pages: + async for page_ in ( + await client.list_instance_configs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.GetInstanceConfigRequest, dict,] + "request_type", + [ + spanner_instance_admin.GetInstanceConfigRequest, + dict, + ], ) def test_get_instance_config(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1088,7 +1154,8 @@ def test_get_instance_config_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1107,7 +1174,8 @@ async def test_get_instance_config_async( request_type=spanner_instance_admin.GetInstanceConfigRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1146,7 +1214,9 @@ async def test_get_instance_config_async_from_dict(): def test_get_instance_config_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -1168,7 +1238,10 @@ def test_get_instance_config_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1199,11 +1272,16 @@ async def test_get_instance_config_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_get_instance_config_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1213,7 +1291,9 @@ def test_get_instance_config_flattened(): call.return_value = spanner_instance_admin.InstanceConfig() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_instance_config(name="name_value",) + client.get_instance_config( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1225,13 +1305,16 @@ def test_get_instance_config_flattened(): def test_get_instance_config_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_instance_config( - spanner_instance_admin.GetInstanceConfigRequest(), name="name_value", + spanner_instance_admin.GetInstanceConfigRequest(), + name="name_value", ) @@ -1253,7 +1336,9 @@ async def test_get_instance_config_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_instance_config(name="name_value",) + response = await client.get_instance_config( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1274,16 +1359,22 @@ async def test_get_instance_config_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_instance_config( - spanner_instance_admin.GetInstanceConfigRequest(), name="name_value", + spanner_instance_admin.GetInstanceConfigRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.ListInstancesRequest, dict,] + "request_type", + [ + spanner_instance_admin.ListInstancesRequest, + dict, + ], ) def test_list_instances(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1312,7 +1403,8 @@ def test_list_instances_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1329,7 +1421,8 @@ async def test_list_instances_async( request_type=spanner_instance_admin.ListInstancesRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1362,7 +1455,9 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -1382,7 +1477,10 @@ def test_list_instances_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1411,11 +1509,16 @@ async def test_list_instances_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_list_instances_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_instances), "__call__") as call: @@ -1423,7 +1526,9 @@ def test_list_instances_flattened(): call.return_value = spanner_instance_admin.ListInstancesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_instances(parent="parent_value",) + client.list_instances( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1435,13 +1540,16 @@ def test_list_instances_flattened(): def test_list_instances_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_instances( - spanner_instance_admin.ListInstancesRequest(), parent="parent_value", + spanner_instance_admin.ListInstancesRequest(), + parent="parent_value", ) @@ -1461,7 +1569,9 @@ async def test_list_instances_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_instances(parent="parent_value",) + response = await client.list_instances( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1482,13 +1592,15 @@ async def test_list_instances_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_instances( - spanner_instance_admin.ListInstancesRequest(), parent="parent_value", + spanner_instance_admin.ListInstancesRequest(), + parent="parent_value", ) def test_list_instances_pager(transport_name: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1504,10 +1616,14 @@ def test_list_instances_pager(transport_name: str = "grpc"): next_page_token="abc", ), spanner_instance_admin.ListInstancesResponse( - instances=[], next_page_token="def", + instances=[], + next_page_token="def", ), spanner_instance_admin.ListInstancesResponse( - instances=[spanner_instance_admin.Instance(),], next_page_token="ghi", + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token="ghi", ), spanner_instance_admin.ListInstancesResponse( instances=[ @@ -1533,7 +1649,8 @@ def test_list_instances_pager(transport_name: str = "grpc"): def test_list_instances_pages(transport_name: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1549,10 +1666,14 @@ def test_list_instances_pages(transport_name: str = "grpc"): next_page_token="abc", ), spanner_instance_admin.ListInstancesResponse( - instances=[], next_page_token="def", + instances=[], + next_page_token="def", ), spanner_instance_admin.ListInstancesResponse( - instances=[spanner_instance_admin.Instance(),], next_page_token="ghi", + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token="ghi", ), spanner_instance_admin.ListInstancesResponse( instances=[ @@ -1569,7 +1690,9 @@ def test_list_instances_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_instances_async_pager(): - client = InstanceAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1586,10 +1709,14 @@ async def test_list_instances_async_pager(): next_page_token="abc", ), spanner_instance_admin.ListInstancesResponse( - instances=[], next_page_token="def", + instances=[], + next_page_token="def", ), spanner_instance_admin.ListInstancesResponse( - instances=[spanner_instance_admin.Instance(),], next_page_token="ghi", + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token="ghi", ), spanner_instance_admin.ListInstancesResponse( instances=[ @@ -1599,10 +1726,12 @@ async def test_list_instances_async_pager(): ), RuntimeError, ) - async_pager = await client.list_instances(request={},) + async_pager = await client.list_instances( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1611,7 +1740,9 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): - client = InstanceAdminAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1628,10 +1759,14 @@ async def test_list_instances_async_pages(): next_page_token="abc", ), spanner_instance_admin.ListInstancesResponse( - instances=[], next_page_token="def", + instances=[], + next_page_token="def", ), spanner_instance_admin.ListInstancesResponse( - instances=[spanner_instance_admin.Instance(),], next_page_token="ghi", + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token="ghi", ), spanner_instance_admin.ListInstancesResponse( instances=[ @@ -1642,18 +1777,25 @@ async def test_list_instances_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_instances(request={})).pages: + async for page_ in ( + await client.list_instances(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.GetInstanceRequest, dict,] + "request_type", + [ + spanner_instance_admin.GetInstanceRequest, + dict, + ], ) def test_get_instance(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1694,7 +1836,8 @@ def test_get_instance_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1711,7 +1854,8 @@ async def test_get_instance_async( request_type=spanner_instance_admin.GetInstanceRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1756,7 +1900,9 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -1776,7 +1922,10 @@ def test_get_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1805,11 +1954,16 @@ async def test_get_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_get_instance_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_instance), "__call__") as call: @@ -1817,7 +1971,9 @@ def test_get_instance_flattened(): call.return_value = spanner_instance_admin.Instance() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_instance(name="name_value",) + client.get_instance( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1829,13 +1985,16 @@ def test_get_instance_flattened(): def test_get_instance_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_instance( - spanner_instance_admin.GetInstanceRequest(), name="name_value", + spanner_instance_admin.GetInstanceRequest(), + name="name_value", ) @@ -1855,7 +2014,9 @@ async def test_get_instance_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_instance(name="name_value",) + response = await client.get_instance( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1876,16 +2037,22 @@ async def test_get_instance_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_instance( - spanner_instance_admin.GetInstanceRequest(), name="name_value", + spanner_instance_admin.GetInstanceRequest(), + name="name_value", ) @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.CreateInstanceRequest, dict,] + "request_type", + [ + spanner_instance_admin.CreateInstanceRequest, + dict, + ], ) def test_create_instance(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1911,7 +2078,8 @@ def test_create_instance_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1928,7 +2096,8 @@ async def test_create_instance_async( request_type=spanner_instance_admin.CreateInstanceRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1958,7 +2127,9 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -1978,7 +2149,10 @@ def test_create_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2007,11 +2181,16 @@ async def test_create_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent/value", + ) in kw["metadata"] def test_create_instance_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_instance), "__call__") as call: @@ -2041,7 +2220,9 @@ def test_create_instance_flattened(): def test_create_instance_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2109,11 +2290,16 @@ async def test_create_instance_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.UpdateInstanceRequest, dict,] + "request_type", + [ + spanner_instance_admin.UpdateInstanceRequest, + dict, + ], ) def test_update_instance(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2139,7 +2325,8 @@ def test_update_instance_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2156,7 +2343,8 @@ async def test_update_instance_async( request_type=spanner_instance_admin.UpdateInstanceRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2186,7 +2374,9 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -2206,9 +2396,10 @@ def test_update_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "instance.name=instance.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "instance.name=instance.name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2237,13 +2428,16 @@ async def test_update_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "instance.name=instance.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "instance.name=instance.name/value", + ) in kw["metadata"] def test_update_instance_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_instance), "__call__") as call: @@ -2269,7 +2463,9 @@ def test_update_instance_flattened(): def test_update_instance_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2331,11 +2527,16 @@ async def test_update_instance_flattened_error_async(): @pytest.mark.parametrize( - "request_type", [spanner_instance_admin.DeleteInstanceRequest, dict,] + "request_type", + [ + spanner_instance_admin.DeleteInstanceRequest, + dict, + ], ) def test_delete_instance(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2361,7 +2562,8 @@ def test_delete_instance_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2378,7 +2580,8 @@ async def test_delete_instance_async( request_type=spanner_instance_admin.DeleteInstanceRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2406,7 +2609,9 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -2426,7 +2631,10 @@ def test_delete_instance_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2453,11 +2661,16 @@ async def test_delete_instance_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_delete_instance_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_instance), "__call__") as call: @@ -2465,7 +2678,9 @@ def test_delete_instance_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_instance(name="name_value",) + client.delete_instance( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2477,13 +2692,16 @@ def test_delete_instance_flattened(): def test_delete_instance_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_instance( - spanner_instance_admin.DeleteInstanceRequest(), name="name_value", + spanner_instance_admin.DeleteInstanceRequest(), + name="name_value", ) @@ -2501,7 +2719,9 @@ async def test_delete_instance_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_instance(name="name_value",) + response = await client.delete_instance( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2522,14 +2742,22 @@ async def test_delete_instance_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_instance( - spanner_instance_admin.DeleteInstanceRequest(), name="name_value", + spanner_instance_admin.DeleteInstanceRequest(), + name="name_value", ) -@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + iam_policy_pb2.SetIamPolicyRequest, + dict, + ], +) def test_set_iam_policy(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2539,7 +2767,10 @@ def test_set_iam_policy(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) response = client.set_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2557,7 +2788,8 @@ def test_set_iam_policy_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2573,7 +2805,8 @@ async def test_set_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2584,7 +2817,10 @@ async def test_set_iam_policy_async( with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy_pb2.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) ) response = await client.set_iam_policy(request) @@ -2605,7 +2841,9 @@ async def test_set_iam_policy_async_from_dict(): def test_set_iam_policy_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -2625,7 +2863,10 @@ def test_set_iam_policy_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2652,11 +2893,16 @@ async def test_set_iam_policy_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] def test_set_iam_policy_from_dict_foreign(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. @@ -2665,13 +2911,16 @@ def test_set_iam_policy_from_dict_foreign(): request={ "resource": "resource_value", "policy": policy_pb2.Policy(version=774), + "update_mask": field_mask_pb2.FieldMask(paths=["paths_value"]), } ) call.assert_called() def test_set_iam_policy_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -2679,7 +2928,9 @@ def test_set_iam_policy_flattened(): call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.set_iam_policy(resource="resource_value",) + client.set_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2691,13 +2942,16 @@ def test_set_iam_policy_flattened(): def test_set_iam_policy_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) @@ -2715,7 +2969,9 @@ async def test_set_iam_policy_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.set_iam_policy(resource="resource_value",) + response = await client.set_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2736,14 +2992,22 @@ async def test_set_iam_policy_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.SetIamPolicyRequest(), + resource="resource_value", ) -@pytest.mark.parametrize("request_type", [iam_policy_pb2.GetIamPolicyRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + iam_policy_pb2.GetIamPolicyRequest, + dict, + ], +) def test_get_iam_policy(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2753,7 +3017,10 @@ def test_get_iam_policy(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy(version=774, etag=b"etag_blob",) + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) response = client.get_iam_policy(request) # Establish that the underlying gRPC stub method was called. @@ -2771,7 +3038,8 @@ def test_get_iam_policy_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2787,7 +3055,8 @@ async def test_get_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2798,7 +3067,10 @@ async def test_get_iam_policy_async( with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - policy_pb2.Policy(version=774, etag=b"etag_blob",) + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) ) response = await client.get_iam_policy(request) @@ -2819,7 +3091,9 @@ async def test_get_iam_policy_async_from_dict(): def test_get_iam_policy_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -2839,7 +3113,10 @@ def test_get_iam_policy_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2866,11 +3143,16 @@ async def test_get_iam_policy_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] def test_get_iam_policy_from_dict_foreign(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. @@ -2885,7 +3167,9 @@ def test_get_iam_policy_from_dict_foreign(): def test_get_iam_policy_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -2893,7 +3177,9 @@ def test_get_iam_policy_flattened(): call.return_value = policy_pb2.Policy() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_iam_policy(resource="resource_value",) + client.get_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2905,13 +3191,16 @@ def test_get_iam_policy_flattened(): def test_get_iam_policy_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.GetIamPolicyRequest(), + resource="resource_value", ) @@ -2929,7 +3218,9 @@ async def test_get_iam_policy_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_iam_policy(resource="resource_value",) + response = await client.get_iam_policy( + resource="resource_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -2950,16 +3241,22 @@ async def test_get_iam_policy_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), resource="resource_value", + iam_policy_pb2.GetIamPolicyRequest(), + resource="resource_value", ) @pytest.mark.parametrize( - "request_type", [iam_policy_pb2.TestIamPermissionsRequest, dict,] + "request_type", + [ + iam_policy_pb2.TestIamPermissionsRequest, + dict, + ], ) def test_test_iam_permissions(request_type, transport: str = "grpc"): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2990,7 +3287,8 @@ def test_test_iam_permissions_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 = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3009,7 +3307,8 @@ async def test_test_iam_permissions_async( request_type=iam_policy_pb2.TestIamPermissionsRequest, ): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3044,7 +3343,9 @@ async def test_test_iam_permissions_async_from_dict(): def test_test_iam_permissions_field_headers(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + 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. @@ -3066,7 +3367,10 @@ def test_test_iam_permissions_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3097,11 +3401,16 @@ async def test_test_iam_permissions_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] def test_test_iam_permissions_from_dict_foreign(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.test_iam_permissions), "__call__" @@ -3118,7 +3427,9 @@ def test_test_iam_permissions_from_dict_foreign(): def test_test_iam_permissions_flattened(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3129,7 +3440,8 @@ def test_test_iam_permissions_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.test_iam_permissions( - resource="resource_value", permissions=["permissions_value"], + resource="resource_value", + permissions=["permissions_value"], ) # Establish that the underlying call was made with the expected @@ -3145,7 +3457,9 @@ def test_test_iam_permissions_flattened(): def test_test_iam_permissions_flattened_error(): - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3176,7 +3490,8 @@ async def test_test_iam_permissions_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.test_iam_permissions( - resource="resource_value", permissions=["permissions_value"], + resource="resource_value", + permissions=["permissions_value"], ) # Establish that the underlying call was made with the expected @@ -3214,7 +3529,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -3234,7 +3550,10 @@ def test_credentials_transport_error(): options = client_options.ClientOptions() options.api_key = "api_key" with pytest.raises(ValueError): - client = InstanceAdminClient(client_options=options, transport=transport,) + client = InstanceAdminClient( + client_options=options, + transport=transport, + ) # It is an error to provide an api_key and a credential. options = mock.Mock() @@ -3250,7 +3569,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = InstanceAdminClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -3293,10 +3613,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = InstanceAdminClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = InstanceAdminClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.InstanceAdminGrpcTransport,) + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.InstanceAdminGrpcTransport, + ) def test_instance_admin_base_transport_error(): @@ -3344,6 +3682,14 @@ def test_instance_admin_base_transport(): with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_instance_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -3355,7 +3701,8 @@ def test_instance_admin_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.InstanceAdminTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -3500,24 +3847,40 @@ def test_instance_admin_grpc_transport_client_cert_source_for_mtls(transport_cla ) -def test_instance_admin_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_instance_admin_host_no_port(transport_name): client = InstanceAdminClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="spanner.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") -def test_instance_admin_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_instance_admin_host_with_port(transport_name): client = InstanceAdminClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="spanner.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "spanner.googleapis.com:8000" + assert client.transport._host == ("spanner.googleapis.com:8000") def test_instance_admin_grpc_transport_channel(): @@ -3525,7 +3888,8 @@ def test_instance_admin_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.InstanceAdminGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3537,7 +3901,8 @@ def test_instance_admin_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.InstanceAdminGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3644,12 +4009,16 @@ def test_instance_admin_transport_channel_mtls_with_adc(transport_class): def test_instance_admin_grpc_lro_client(): client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3657,12 +4026,16 @@ def test_instance_admin_grpc_lro_client(): def test_instance_admin_grpc_lro_async_client(): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3672,7 +4045,8 @@ def test_instance_path(): project = "squid" instance = "clam" expected = "projects/{project}/instances/{instance}".format( - project=project, instance=instance, + project=project, + instance=instance, ) actual = InstanceAdminClient.instance_path(project, instance) assert expected == actual @@ -3694,7 +4068,8 @@ def test_instance_config_path(): project = "oyster" instance_config = "nudibranch" expected = "projects/{project}/instanceConfigs/{instance_config}".format( - project=project, instance_config=instance_config, + project=project, + instance_config=instance_config, ) actual = InstanceAdminClient.instance_config_path(project, instance_config) assert expected == actual @@ -3734,7 +4109,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = InstanceAdminClient.common_folder_path(folder) assert expected == actual @@ -3752,7 +4129,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = InstanceAdminClient.common_organization_path(organization) assert expected == actual @@ -3770,7 +4149,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = InstanceAdminClient.common_project_path(project) assert expected == actual @@ -3790,7 +4171,8 @@ def test_common_location_path(): project = "oyster" location = "nudibranch" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = InstanceAdminClient.common_location_path(project, location) assert expected == actual @@ -3815,7 +4197,8 @@ def test_client_with_default_client_info(): transports.InstanceAdminTransport, "_prep_wrapped_messages" ) as prep: client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3824,7 +4207,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = InstanceAdminClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3832,7 +4216,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close" diff --git a/tests/unit/gapic/spanner_v1/__init__.py b/tests/unit/gapic/spanner_v1/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/spanner_v1/__init__.py +++ b/tests/unit/gapic/spanner_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/spanner_v1/test_spanner.py b/tests/unit/gapic/spanner_v1/test_spanner.py index c9fe4fadb1..d4df289e48 100644 --- a/tests/unit/gapic/spanner_v1/test_spanner.py +++ b/tests/unit/gapic/spanner_v1/test_spanner.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -88,19 +88,25 @@ def test__get_default_mtls_endpoint(): assert SpannerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [SpannerClient, SpannerAsyncClient,]) -def test_spanner_client_from_service_account_info(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (SpannerClient, "grpc"), + (SpannerAsyncClient, "grpc_asyncio"), + ], +) +def test_spanner_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") @pytest.mark.parametrize( @@ -126,22 +132,32 @@ def test_spanner_client_service_account_always_use_jwt(transport_class, transpor use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [SpannerClient, SpannerAsyncClient,]) -def test_spanner_client_from_service_account_file(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (SpannerClient, "grpc"), + (SpannerAsyncClient, "grpc_asyncio"), + ], +) +def test_spanner_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") def test_spanner_client_get_transport_class(): @@ -465,7 +481,9 @@ def test_spanner_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -596,10 +614,17 @@ def test_spanner_client_create_channel_credentials_file( ) -@pytest.mark.parametrize("request_type", [spanner.CreateSessionRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.CreateSessionRequest, + dict, + ], +) def test_create_session(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -609,7 +634,9 @@ def test_create_session(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_session), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = spanner.Session(name="name_value",) + call.return_value = spanner.Session( + name="name_value", + ) response = client.create_session(request) # Establish that the underlying gRPC stub method was called. @@ -626,7 +653,8 @@ def test_create_session_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -642,7 +670,8 @@ async def test_create_session_async( transport: str = "grpc_asyncio", request_type=spanner.CreateSessionRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -653,7 +682,9 @@ async def test_create_session_async( with mock.patch.object(type(client.transport.create_session), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - spanner.Session(name="name_value",) + spanner.Session( + name="name_value", + ) ) response = await client.create_session(request) @@ -673,7 +704,9 @@ async def test_create_session_async_from_dict(): def test_create_session_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -693,12 +726,17 @@ def test_create_session_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_session_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -718,11 +756,16 @@ async def test_create_session_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] def test_create_session_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_session), "__call__") as call: @@ -730,7 +773,9 @@ def test_create_session_flattened(): call.return_value = spanner.Session() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_session(database="database_value",) + client.create_session( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -742,19 +787,24 @@ def test_create_session_flattened(): def test_create_session_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.create_session( - spanner.CreateSessionRequest(), database="database_value", + spanner.CreateSessionRequest(), + database="database_value", ) @pytest.mark.asyncio async def test_create_session_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_session), "__call__") as call: @@ -764,7 +814,9 @@ async def test_create_session_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_session(database="database_value",) + response = await client.create_session( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -777,20 +829,30 @@ async def test_create_session_flattened_async(): @pytest.mark.asyncio async def test_create_session_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.create_session( - spanner.CreateSessionRequest(), database="database_value", + spanner.CreateSessionRequest(), + database="database_value", ) -@pytest.mark.parametrize("request_type", [spanner.BatchCreateSessionsRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.BatchCreateSessionsRequest, + dict, + ], +) def test_batch_create_sessions(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -818,7 +880,8 @@ def test_batch_create_sessions_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -836,7 +899,8 @@ async def test_batch_create_sessions_async( transport: str = "grpc_asyncio", request_type=spanner.BatchCreateSessionsRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -868,7 +932,9 @@ async def test_batch_create_sessions_async_from_dict(): def test_batch_create_sessions_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -890,12 +956,17 @@ def test_batch_create_sessions_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_batch_create_sessions_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -919,11 +990,16 @@ async def test_batch_create_sessions_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] def test_batch_create_sessions_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -934,7 +1010,8 @@ def test_batch_create_sessions_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.batch_create_sessions( - database="database_value", session_count=1420, + database="database_value", + session_count=1420, ) # Establish that the underlying call was made with the expected @@ -950,7 +1027,9 @@ def test_batch_create_sessions_flattened(): def test_batch_create_sessions_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -964,7 +1043,9 @@ def test_batch_create_sessions_flattened_error(): @pytest.mark.asyncio async def test_batch_create_sessions_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -979,7 +1060,8 @@ async def test_batch_create_sessions_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.batch_create_sessions( - database="database_value", session_count=1420, + database="database_value", + session_count=1420, ) # Establish that the underlying call was made with the expected @@ -996,7 +1078,9 @@ async def test_batch_create_sessions_flattened_async(): @pytest.mark.asyncio async def test_batch_create_sessions_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1008,10 +1092,17 @@ async def test_batch_create_sessions_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [spanner.GetSessionRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.GetSessionRequest, + dict, + ], +) def test_get_session(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1021,7 +1112,9 @@ def test_get_session(request_type, transport: str = "grpc"): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_session), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = spanner.Session(name="name_value",) + call.return_value = spanner.Session( + name="name_value", + ) response = client.get_session(request) # Establish that the underlying gRPC stub method was called. @@ -1038,7 +1131,8 @@ def test_get_session_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1054,7 +1148,8 @@ async def test_get_session_async( transport: str = "grpc_asyncio", request_type=spanner.GetSessionRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1065,7 +1160,9 @@ async def test_get_session_async( with mock.patch.object(type(client.transport.get_session), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - spanner.Session(name="name_value",) + spanner.Session( + name="name_value", + ) ) response = await client.get_session(request) @@ -1085,7 +1182,9 @@ async def test_get_session_async_from_dict(): def test_get_session_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -1105,12 +1204,17 @@ def test_get_session_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_session_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -1130,11 +1234,16 @@ async def test_get_session_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_get_session_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_session), "__call__") as call: @@ -1142,7 +1251,9 @@ def test_get_session_flattened(): call.return_value = spanner.Session() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_session(name="name_value",) + client.get_session( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1154,19 +1265,24 @@ def test_get_session_flattened(): def test_get_session_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_session( - spanner.GetSessionRequest(), name="name_value", + spanner.GetSessionRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_session_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_session), "__call__") as call: @@ -1176,7 +1292,9 @@ async def test_get_session_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_session(name="name_value",) + response = await client.get_session( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1189,20 +1307,30 @@ async def test_get_session_flattened_async(): @pytest.mark.asyncio async def test_get_session_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_session( - spanner.GetSessionRequest(), name="name_value", + spanner.GetSessionRequest(), + name="name_value", ) -@pytest.mark.parametrize("request_type", [spanner.ListSessionsRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.ListSessionsRequest, + dict, + ], +) def test_list_sessions(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1231,7 +1359,8 @@ def test_list_sessions_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1247,7 +1376,8 @@ async def test_list_sessions_async( transport: str = "grpc_asyncio", request_type=spanner.ListSessionsRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1258,7 +1388,9 @@ async def test_list_sessions_async( with mock.patch.object(type(client.transport.list_sessions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - spanner.ListSessionsResponse(next_page_token="next_page_token_value",) + spanner.ListSessionsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_sessions(request) @@ -1278,7 +1410,9 @@ async def test_list_sessions_async_from_dict(): def test_list_sessions_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -1298,12 +1432,17 @@ def test_list_sessions_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_sessions_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -1325,11 +1464,16 @@ async def test_list_sessions_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "database=database/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "database=database/value", + ) in kw["metadata"] def test_list_sessions_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sessions), "__call__") as call: @@ -1337,7 +1481,9 @@ def test_list_sessions_flattened(): call.return_value = spanner.ListSessionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_sessions(database="database_value",) + client.list_sessions( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1349,19 +1495,24 @@ def test_list_sessions_flattened(): def test_list_sessions_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_sessions( - spanner.ListSessionsRequest(), database="database_value", + spanner.ListSessionsRequest(), + database="database_value", ) @pytest.mark.asyncio async def test_list_sessions_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_sessions), "__call__") as call: @@ -1373,7 +1524,9 @@ async def test_list_sessions_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_sessions(database="database_value",) + response = await client.list_sessions( + database="database_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1386,19 +1539,23 @@ async def test_list_sessions_flattened_async(): @pytest.mark.asyncio async def test_list_sessions_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_sessions( - spanner.ListSessionsRequest(), database="database_value", + spanner.ListSessionsRequest(), + database="database_value", ) def test_list_sessions_pager(transport_name: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1406,15 +1563,28 @@ def test_list_sessions_pager(transport_name: str = "grpc"): # Set the response to a series of pages. call.side_effect = ( spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], next_page_token="abc", ), - spanner.ListSessionsResponse(sessions=[], next_page_token="def",), spanner.ListSessionsResponse( - sessions=[spanner.Session(),], next_page_token="ghi", + sessions=[], + next_page_token="def", ), spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + ], + next_page_token="ghi", + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], ), RuntimeError, ) @@ -1434,7 +1604,8 @@ def test_list_sessions_pager(transport_name: str = "grpc"): def test_list_sessions_pages(transport_name: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1442,15 +1613,28 @@ def test_list_sessions_pages(transport_name: str = "grpc"): # Set the response to a series of pages. call.side_effect = ( spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], next_page_token="abc", ), - spanner.ListSessionsResponse(sessions=[], next_page_token="def",), spanner.ListSessionsResponse( - sessions=[spanner.Session(),], next_page_token="ghi", + sessions=[], + next_page_token="def", ), spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + ], + next_page_token="ghi", + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], ), RuntimeError, ) @@ -1461,7 +1645,9 @@ def test_list_sessions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_sessions_async_pager(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1470,22 +1656,37 @@ async def test_list_sessions_async_pager(): # Set the response to a series of pages. call.side_effect = ( spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], next_page_token="abc", ), - spanner.ListSessionsResponse(sessions=[], next_page_token="def",), spanner.ListSessionsResponse( - sessions=[spanner.Session(),], next_page_token="ghi", + sessions=[], + next_page_token="def", ), spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + ], + next_page_token="ghi", + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], ), RuntimeError, ) - async_pager = await client.list_sessions(request={},) + async_pager = await client.list_sessions( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1494,7 +1695,9 @@ async def test_list_sessions_async_pager(): @pytest.mark.asyncio async def test_list_sessions_async_pages(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1503,29 +1706,51 @@ async def test_list_sessions_async_pages(): # Set the response to a series of pages. call.side_effect = ( spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], next_page_token="abc", ), - spanner.ListSessionsResponse(sessions=[], next_page_token="def",), spanner.ListSessionsResponse( - sessions=[spanner.Session(),], next_page_token="ghi", + sessions=[], + next_page_token="def", ), spanner.ListSessionsResponse( - sessions=[spanner.Session(), spanner.Session(),], + sessions=[ + spanner.Session(), + ], + next_page_token="ghi", + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_sessions(request={})).pages: + async for page_ in ( + await client.list_sessions(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -@pytest.mark.parametrize("request_type", [spanner.DeleteSessionRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.DeleteSessionRequest, + dict, + ], +) def test_delete_session(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1551,7 +1776,8 @@ def test_delete_session_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1567,7 +1793,8 @@ async def test_delete_session_async( transport: str = "grpc_asyncio", request_type=spanner.DeleteSessionRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1595,7 +1822,9 @@ async def test_delete_session_async_from_dict(): def test_delete_session_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -1615,12 +1844,17 @@ def test_delete_session_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_session_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -1640,11 +1874,16 @@ async def test_delete_session_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name/value", + ) in kw["metadata"] def test_delete_session_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_session), "__call__") as call: @@ -1652,7 +1891,9 @@ def test_delete_session_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_session(name="name_value",) + client.delete_session( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1664,19 +1905,24 @@ def test_delete_session_flattened(): def test_delete_session_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_session( - spanner.DeleteSessionRequest(), name="name_value", + spanner.DeleteSessionRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_session_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_session), "__call__") as call: @@ -1686,7 +1932,9 @@ async def test_delete_session_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_session(name="name_value",) + response = await client.delete_session( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. @@ -1699,20 +1947,30 @@ async def test_delete_session_flattened_async(): @pytest.mark.asyncio async def test_delete_session_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_session( - spanner.DeleteSessionRequest(), name="name_value", + spanner.DeleteSessionRequest(), + name="name_value", ) -@pytest.mark.parametrize("request_type", [spanner.ExecuteSqlRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.ExecuteSqlRequest, + dict, + ], +) def test_execute_sql(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1738,7 +1996,8 @@ def test_execute_sql_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1754,7 +2013,8 @@ async def test_execute_sql_async( transport: str = "grpc_asyncio", request_type=spanner.ExecuteSqlRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1784,7 +2044,9 @@ async def test_execute_sql_async_from_dict(): def test_execute_sql_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -1804,12 +2066,17 @@ def test_execute_sql_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_execute_sql_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -1831,13 +2098,23 @@ async def test_execute_sql_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [spanner.ExecuteSqlRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.ExecuteSqlRequest, + dict, + ], +) def test_execute_streaming_sql(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1866,7 +2143,8 @@ def test_execute_streaming_sql_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1884,7 +2162,8 @@ async def test_execute_streaming_sql_async( transport: str = "grpc_asyncio", request_type=spanner.ExecuteSqlRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1918,7 +2197,9 @@ async def test_execute_streaming_sql_async_from_dict(): def test_execute_streaming_sql_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -1940,12 +2221,17 @@ def test_execute_streaming_sql_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_execute_streaming_sql_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -1970,13 +2256,23 @@ async def test_execute_streaming_sql_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [spanner.ExecuteBatchDmlRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.ExecuteBatchDmlRequest, + dict, + ], +) def test_execute_batch_dml(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2004,7 +2300,8 @@ def test_execute_batch_dml_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2022,7 +2319,8 @@ async def test_execute_batch_dml_async( transport: str = "grpc_asyncio", request_type=spanner.ExecuteBatchDmlRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2054,7 +2352,9 @@ async def test_execute_batch_dml_async_from_dict(): def test_execute_batch_dml_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -2076,12 +2376,17 @@ def test_execute_batch_dml_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_execute_batch_dml_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -2105,13 +2410,23 @@ async def test_execute_batch_dml_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [spanner.ReadRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.ReadRequest, + dict, + ], +) def test_read(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2137,7 +2452,8 @@ def test_read_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2153,7 +2469,8 @@ async def test_read_async( transport: str = "grpc_asyncio", request_type=spanner.ReadRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2183,7 +2500,9 @@ async def test_read_async_from_dict(): def test_read_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -2203,12 +2522,17 @@ def test_read_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_read_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -2230,13 +2554,23 @@ async def test_read_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [spanner.ReadRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.ReadRequest, + dict, + ], +) def test_streaming_read(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2263,7 +2597,8 @@ def test_streaming_read_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2279,7 +2614,8 @@ async def test_streaming_read_async( transport: str = "grpc_asyncio", request_type=spanner.ReadRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2311,7 +2647,9 @@ async def test_streaming_read_async_from_dict(): def test_streaming_read_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -2331,12 +2669,17 @@ def test_streaming_read_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_streaming_read_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -2359,13 +2702,23 @@ async def test_streaming_read_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [spanner.BeginTransactionRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.BeginTransactionRequest, + dict, + ], +) def test_begin_transaction(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2377,7 +2730,9 @@ def test_begin_transaction(request_type, transport: str = "grpc"): type(client.transport.begin_transaction), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = transaction.Transaction(id=b"id_blob",) + call.return_value = transaction.Transaction( + id=b"id_blob", + ) response = client.begin_transaction(request) # Establish that the underlying gRPC stub method was called. @@ -2394,7 +2749,8 @@ def test_begin_transaction_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2412,7 +2768,8 @@ async def test_begin_transaction_async( transport: str = "grpc_asyncio", request_type=spanner.BeginTransactionRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2425,7 +2782,9 @@ async def test_begin_transaction_async( ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - transaction.Transaction(id=b"id_blob",) + transaction.Transaction( + id=b"id_blob", + ) ) response = await client.begin_transaction(request) @@ -2445,7 +2804,9 @@ async def test_begin_transaction_async_from_dict(): def test_begin_transaction_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -2467,12 +2828,17 @@ def test_begin_transaction_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_begin_transaction_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -2496,11 +2862,16 @@ async def test_begin_transaction_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] def test_begin_transaction_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2528,7 +2899,9 @@ def test_begin_transaction_flattened(): def test_begin_transaction_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2542,7 +2915,9 @@ def test_begin_transaction_flattened_error(): @pytest.mark.asyncio async def test_begin_transaction_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2575,7 +2950,9 @@ async def test_begin_transaction_flattened_async(): @pytest.mark.asyncio async def test_begin_transaction_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2587,10 +2964,17 @@ async def test_begin_transaction_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [spanner.CommitRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.CommitRequest, + dict, + ], +) def test_commit(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2616,7 +3000,8 @@ def test_commit_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2632,7 +3017,8 @@ async def test_commit_async( transport: str = "grpc_asyncio", request_type=spanner.CommitRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2662,7 +3048,9 @@ async def test_commit_async_from_dict(): def test_commit_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -2682,12 +3070,17 @@ def test_commit_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_commit_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -2709,11 +3102,16 @@ async def test_commit_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] def test_commit_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.commit), "__call__") as call: @@ -2748,7 +3146,9 @@ def test_commit_flattened(): def test_commit_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2766,7 +3166,9 @@ def test_commit_flattened_error(): @pytest.mark.asyncio async def test_commit_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.commit), "__call__") as call: @@ -2806,7 +3208,9 @@ async def test_commit_flattened_async(): @pytest.mark.asyncio async def test_commit_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2822,10 +3226,17 @@ async def test_commit_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [spanner.RollbackRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.RollbackRequest, + dict, + ], +) def test_rollback(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2851,7 +3262,8 @@ def test_rollback_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2867,7 +3279,8 @@ async def test_rollback_async( transport: str = "grpc_asyncio", request_type=spanner.RollbackRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2895,7 +3308,9 @@ async def test_rollback_async_from_dict(): def test_rollback_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -2915,12 +3330,17 @@ def test_rollback_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_rollback_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -2940,11 +3360,16 @@ async def test_rollback_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] def test_rollback_flattened(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.rollback), "__call__") as call: @@ -2953,7 +3378,8 @@ def test_rollback_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.rollback( - session="session_value", transaction_id=b"transaction_id_blob", + session="session_value", + transaction_id=b"transaction_id_blob", ) # Establish that the underlying call was made with the expected @@ -2969,7 +3395,9 @@ def test_rollback_flattened(): def test_rollback_flattened_error(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2983,7 +3411,9 @@ def test_rollback_flattened_error(): @pytest.mark.asyncio async def test_rollback_flattened_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.rollback), "__call__") as call: @@ -2994,7 +3424,8 @@ async def test_rollback_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.rollback( - session="session_value", transaction_id=b"transaction_id_blob", + session="session_value", + transaction_id=b"transaction_id_blob", ) # Establish that the underlying call was made with the expected @@ -3011,7 +3442,9 @@ async def test_rollback_flattened_async(): @pytest.mark.asyncio async def test_rollback_flattened_error_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3023,10 +3456,17 @@ async def test_rollback_flattened_error_async(): ) -@pytest.mark.parametrize("request_type", [spanner.PartitionQueryRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.PartitionQueryRequest, + dict, + ], +) def test_partition_query(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3052,7 +3492,8 @@ def test_partition_query_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3068,7 +3509,8 @@ async def test_partition_query_async( transport: str = "grpc_asyncio", request_type=spanner.PartitionQueryRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3098,7 +3540,9 @@ async def test_partition_query_async_from_dict(): def test_partition_query_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -3118,12 +3562,17 @@ def test_partition_query_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_partition_query_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -3145,13 +3594,23 @@ async def test_partition_query_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [spanner.PartitionReadRequest, dict,]) +@pytest.mark.parametrize( + "request_type", + [ + spanner.PartitionReadRequest, + dict, + ], +) def test_partition_read(request_type, transport: str = "grpc"): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3177,7 +3636,8 @@ def test_partition_read_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 = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3193,7 +3653,8 @@ async def test_partition_read_async( transport: str = "grpc_asyncio", request_type=spanner.PartitionReadRequest ): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3223,7 +3684,9 @@ async def test_partition_read_async_from_dict(): def test_partition_read_field_headers(): - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerClient( + 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. @@ -3243,12 +3706,17 @@ def test_partition_read_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_partition_read_field_headers_async(): - client = SpannerAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = SpannerAsyncClient( + 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. @@ -3270,7 +3738,10 @@ async def test_partition_read_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "session=session/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "session=session/value", + ) in kw["metadata"] def test_credentials_transport_error(): @@ -3280,7 +3751,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -3300,7 +3772,10 @@ def test_credentials_transport_error(): options = client_options.ClientOptions() options.api_key = "api_key" with pytest.raises(ValueError): - client = SpannerClient(client_options=options, transport=transport,) + client = SpannerClient( + client_options=options, + transport=transport, + ) # It is an error to provide an api_key and a credential. options = mock.Mock() @@ -3316,7 +3791,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = SpannerClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -3346,7 +3822,10 @@ def test_transport_get_channel(): @pytest.mark.parametrize( "transport_class", - [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport,], + [ + transports.SpannerGrpcTransport, + transports.SpannerGrpcAsyncIOTransport, + ], ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. @@ -3356,10 +3835,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = SpannerClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = SpannerClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.SpannerGrpcTransport,) + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.SpannerGrpcTransport, + ) def test_spanner_base_transport_error(): @@ -3407,6 +3904,14 @@ def test_spanner_base_transport(): with pytest.raises(NotImplementedError): transport.close() + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + def test_spanner_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file @@ -3418,7 +3923,8 @@ def test_spanner_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpannerTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -3459,7 +3965,10 @@ def test_spanner_auth_adc(): @pytest.mark.parametrize( "transport_class", - [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport,], + [ + transports.SpannerGrpcTransport, + transports.SpannerGrpcAsyncIOTransport, + ], ) def test_spanner_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use @@ -3557,24 +4066,40 @@ def test_spanner_grpc_transport_client_cert_source_for_mtls(transport_class): ) -def test_spanner_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_spanner_host_no_port(transport_name): client = SpannerClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="spanner.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "spanner.googleapis.com:443" + assert client.transport._host == ("spanner.googleapis.com:443") -def test_spanner_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_spanner_host_with_port(transport_name): client = SpannerClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="spanner.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "spanner.googleapis.com:8000" + assert client.transport._host == ("spanner.googleapis.com:8000") def test_spanner_grpc_transport_channel(): @@ -3582,7 +4107,8 @@ def test_spanner_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.SpannerGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3594,7 +4120,8 @@ def test_spanner_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.SpannerGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3698,7 +4225,9 @@ def test_database_path(): instance = "clam" database = "whelk" expected = "projects/{project}/instances/{instance}/databases/{database}".format( - project=project, instance=instance, database=database, + project=project, + instance=instance, + database=database, ) actual = SpannerClient.database_path(project, instance, database) assert expected == actual @@ -3723,7 +4252,10 @@ def test_session_path(): database = "winkle" session = "nautilus" expected = "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}".format( - project=project, instance=instance, database=database, session=session, + project=project, + instance=instance, + database=database, + session=session, ) actual = SpannerClient.session_path(project, instance, database, session) assert expected == actual @@ -3765,7 +4297,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "oyster" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = SpannerClient.common_folder_path(folder) assert expected == actual @@ -3783,7 +4317,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = SpannerClient.common_organization_path(organization) assert expected == actual @@ -3801,7 +4337,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "winkle" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = SpannerClient.common_project_path(project) assert expected == actual @@ -3821,7 +4359,8 @@ def test_common_location_path(): project = "scallop" location = "abalone" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = SpannerClient.common_location_path(project, location) assert expected == actual @@ -3846,7 +4385,8 @@ def test_client_with_default_client_info(): transports.SpannerTransport, "_prep_wrapped_messages" ) as prep: client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3855,7 +4395,8 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SpannerClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3863,7 +4404,8 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) with mock.patch.object( type(getattr(client.transport, "grpc_channel")), "close" diff --git a/tests/unit/spanner_dbapi/test_connect.py b/tests/unit/spanner_dbapi/test_connect.py index f4dfe28a96..948659d595 100644 --- a/tests/unit/spanner_dbapi/test_connect.py +++ b/tests/unit/spanner_dbapi/test_connect.py @@ -70,7 +70,12 @@ def test_w_explicit(self, mock_client): database = instance.database.return_value connection = connect( - INSTANCE, DATABASE, PROJECT, credentials, pool=pool, user_agent=USER_AGENT, + INSTANCE, + DATABASE, + PROJECT, + credentials, + pool=pool, + user_agent=USER_AGENT, ) self.assertIsInstance(connection, Connection) @@ -107,7 +112,9 @@ def test_w_credential_file_path(self, mock_client): factory = mock_client.from_service_account_json factory.assert_called_once_with( - credentials_path, project=PROJECT, client_info=mock.ANY, + credentials_path, + project=PROJECT, + client_info=mock.ANY, ) client_info = factory.call_args_list[0][1]["client_info"] self.assertEqual(client_info.user_agent, USER_AGENT) diff --git a/tests/unit/spanner_dbapi/test_connection.py b/tests/unit/spanner_dbapi/test_connection.py index 0eea3eaf5b..7902de6405 100644 --- a/tests/unit/spanner_dbapi/test_connection.py +++ b/tests/unit/spanner_dbapi/test_connection.py @@ -134,7 +134,11 @@ def test_read_only_not_retried(self): connection.retry_transaction = mock.Mock() cursor = connection.cursor() - cursor._itr = mock.Mock(__next__=mock.Mock(side_effect=Aborted("Aborted"),)) + cursor._itr = mock.Mock( + __next__=mock.Mock( + side_effect=Aborted("Aborted"), + ) + ) cursor.fetchone() cursor.fetchall() @@ -574,7 +578,10 @@ def test_retry_aborted_retry(self, mock_client): connection.retry_transaction() run_mock.assert_has_calls( - (mock.call(statement, retried=True), mock.call(statement, retried=True),) + ( + mock.call(statement, retried=True), + mock.call(statement, retried=True), + ) ) def test_retry_transaction_raise_max_internal_retries(self): @@ -631,7 +638,10 @@ def test_retry_aborted_retry_without_delay(self, mock_client): connection.retry_transaction() run_mock.assert_has_calls( - (mock.call(statement, retried=True), mock.call(statement, retried=True),) + ( + mock.call(statement, retried=True), + mock.call(statement, retried=True), + ) ) def test_retry_transaction_w_multiple_statement(self): diff --git a/tests/unit/spanner_dbapi/test_cursor.py b/tests/unit/spanner_dbapi/test_cursor.py index 51732bc1b0..71e4a96d6e 100644 --- a/tests/unit/spanner_dbapi/test_cursor.py +++ b/tests/unit/spanner_dbapi/test_cursor.py @@ -106,7 +106,9 @@ def test_do_execute_update(self): def run_helper(ret_value): transaction.execute_update.return_value = ret_value res = cursor._do_execute_update( - transaction=transaction, sql="SELECT * WHERE true", params={}, + transaction=transaction, + sql="SELECT * WHERE true", + params={}, ) return res diff --git a/tests/unit/spanner_dbapi/test_parse_utils.py b/tests/unit/spanner_dbapi/test_parse_utils.py index 994b02d615..b0f363299b 100644 --- a/tests/unit/spanner_dbapi/test_parse_utils.py +++ b/tests/unit/spanner_dbapi/test_parse_utils.py @@ -425,5 +425,6 @@ def test_insert_from_select(self): ARGS = [5, "data2", "data3"] self.assertEqual( - parse_insert(SQL, ARGS), {"sql_params_list": [(SQL, ARGS)]}, + parse_insert(SQL, ARGS), + {"sql_params_list": [(SQL, ARGS)]}, ) diff --git a/tests/unit/spanner_dbapi/test_parser.py b/tests/unit/spanner_dbapi/test_parser.py index 994d4966d3..dd99f6fa4b 100644 --- a/tests/unit/spanner_dbapi/test_parser.py +++ b/tests/unit/spanner_dbapi/test_parser.py @@ -172,7 +172,7 @@ def test_a_args_homogeneous(self): from google.cloud.spanner_dbapi.parser import a_args from google.cloud.spanner_dbapi.parser import terminal - a_obj = a_args([a_args([terminal(10 ** i)]) for i in range(10)]) + a_obj = a_args([a_args([terminal(10**i)]) for i in range(10)]) self.assertTrue(a_obj.homogenous()) a_obj = a_args([a_args([[object()]]) for _ in range(10)]) @@ -193,7 +193,7 @@ def test_values(self): from google.cloud.spanner_dbapi.parser import terminal from google.cloud.spanner_dbapi.parser import values - a_obj = a_args([a_args([terminal(10 ** i)]) for i in range(10)]) + a_obj = a_args([a_args([terminal(10**i)]) for i in range(10)]) self.assertEqual(str(values(a_obj)), "VALUES%s" % str(a_obj)) def test_expect(self): diff --git a/tests/unit/test__helpers.py b/tests/unit/test__helpers.py index f6d1539221..b18adfa6fe 100644 --- a/tests/unit/test__helpers.py +++ b/tests/unit/test__helpers.py @@ -113,7 +113,7 @@ def test_w_invalid_bytes(self): def test_w_explicit_unicode(self): from google.protobuf.struct_pb2 import Value - TEXT = u"TEXT" + TEXT = "TEXT" value_pb = self._callFUT(TEXT) self.assertIsInstance(value_pb, Value) self.assertEqual(value_pb.string_value, TEXT) @@ -122,21 +122,21 @@ def test_w_list(self): from google.protobuf.struct_pb2 import Value from google.protobuf.struct_pb2 import ListValue - value_pb = self._callFUT([u"a", u"b", u"c"]) + value_pb = self._callFUT(["a", "b", "c"]) self.assertIsInstance(value_pb, Value) self.assertIsInstance(value_pb.list_value, ListValue) values = value_pb.list_value.values - self.assertEqual([value.string_value for value in values], [u"a", u"b", u"c"]) + self.assertEqual([value.string_value for value in values], ["a", "b", "c"]) def test_w_tuple(self): from google.protobuf.struct_pb2 import Value from google.protobuf.struct_pb2 import ListValue - value_pb = self._callFUT((u"a", u"b", u"c")) + value_pb = self._callFUT(("a", "b", "c")) self.assertIsInstance(value_pb, Value) self.assertIsInstance(value_pb.list_value, ListValue) values = value_pb.list_value.values - self.assertEqual([value.string_value for value in values], [u"a", u"b", u"c"]) + self.assertEqual([value.string_value for value in values], ["a", "b", "c"]) def test_w_bool(self): from google.protobuf.struct_pb2 import Value @@ -290,7 +290,9 @@ def test_w_numeric_precision_and_scale_invalid(self): for value, err_msg in cases: with self.subTest(value=value, err_msg=err_msg): self.assertRaisesRegex( - ValueError, err_msg, lambda: self._callFUT(value), + ValueError, + err_msg, + lambda: self._callFUT(value), ) def test_w_json(self): @@ -321,7 +323,7 @@ def test_empty(self): def test_w_single_value(self): from google.protobuf.struct_pb2 import ListValue - VALUE = u"value" + VALUE = "value" result = self._callFUT(values=[VALUE]) self.assertIsInstance(result, ListValue) self.assertEqual(len(result.values), 1) @@ -330,7 +332,7 @@ def test_w_single_value(self): def test_w_multiple_values(self): from google.protobuf.struct_pb2 import ListValue - VALUE_1 = u"value" + VALUE_1 = "value" VALUE_2 = 42 result = self._callFUT(values=[VALUE_1, VALUE_2]) self.assertIsInstance(result, ListValue) @@ -363,7 +365,7 @@ def test_w_single_values(self): def test_w_multiple_values(self): from google.protobuf.struct_pb2 import ListValue - values = [[0, u"A"], [1, u"B"]] + values = [[0, "A"], [1, "B"]] result = self._callFUT(values=values) self.assertEqual(len(result), len(values)) for found, expected in zip(result, values): @@ -394,7 +396,7 @@ def test_w_string(self): from google.cloud.spanner_v1 import Type from google.cloud.spanner_v1 import TypeCode - VALUE = u"Value" + VALUE = "Value" field_type = Type(code=TypeCode.STRING) value_pb = Value(string_value=VALUE) @@ -537,7 +539,7 @@ def test_w_struct(self): from google.cloud.spanner_v1 import TypeCode from google.cloud.spanner_v1._helpers import _make_list_value_pb - VALUES = [u"phred", 32] + VALUES = ["phred", 32] struct_type_pb = StructType( fields=[ StructType.Field(name="name", type_=Type(code=TypeCode.STRING)), @@ -621,7 +623,7 @@ def test_non_empty(self): from google.cloud.spanner_v1 import TypeCode from google.cloud.spanner_v1._helpers import _make_list_value_pbs - VALUES = [[u"phred", 32], [u"bharney", 31]] + VALUES = [["phred", 32], ["bharney", 31]] struct_type_pb = StructType( fields=[ StructType.Field(name="name", type_=Type(code=TypeCode.STRING)), diff --git a/tests/unit/test_backup.py b/tests/unit/test_backup.py index 035a2c9605..00621c2148 100644 --- a/tests/unit/test_backup.py +++ b/tests/unit/test_backup.py @@ -241,17 +241,23 @@ def test_create_grpc_error(self): self.BACKUP_ID, instance, database=self.DATABASE_NAME, expire_time=timestamp ) - backup_pb = Backup(database=self.DATABASE_NAME, expire_time=timestamp,) + backup_pb = Backup( + database=self.DATABASE_NAME, + expire_time=timestamp, + ) with self.assertRaises(GoogleAPICallError): backup.create() request = CreateBackupRequest( - parent=self.INSTANCE_NAME, backup_id=self.BACKUP_ID, backup=backup_pb, + parent=self.INSTANCE_NAME, + backup_id=self.BACKUP_ID, + backup=backup_pb, ) api.create_backup.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", backup.name)], + request=request, + metadata=[("google-cloud-resource-prefix", backup.name)], ) def test_create_already_exists(self): @@ -269,17 +275,23 @@ def test_create_already_exists(self): self.BACKUP_ID, instance, database=self.DATABASE_NAME, expire_time=timestamp ) - backup_pb = Backup(database=self.DATABASE_NAME, expire_time=timestamp,) + backup_pb = Backup( + database=self.DATABASE_NAME, + expire_time=timestamp, + ) with self.assertRaises(Conflict): backup.create() request = CreateBackupRequest( - parent=self.INSTANCE_NAME, backup_id=self.BACKUP_ID, backup=backup_pb, + parent=self.INSTANCE_NAME, + backup_id=self.BACKUP_ID, + backup=backup_pb, ) api.create_backup.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", backup.name)], + request=request, + metadata=[("google-cloud-resource-prefix", backup.name)], ) def test_create_instance_not_found(self): @@ -297,17 +309,23 @@ def test_create_instance_not_found(self): self.BACKUP_ID, instance, database=self.DATABASE_NAME, expire_time=timestamp ) - backup_pb = Backup(database=self.DATABASE_NAME, expire_time=timestamp,) + backup_pb = Backup( + database=self.DATABASE_NAME, + expire_time=timestamp, + ) with self.assertRaises(NotFound): backup.create() request = CreateBackupRequest( - parent=self.INSTANCE_NAME, backup_id=self.BACKUP_ID, backup=backup_pb, + parent=self.INSTANCE_NAME, + backup_id=self.BACKUP_ID, + backup=backup_pb, ) api.create_backup.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", backup.name)], + request=request, + metadata=[("google-cloud-resource-prefix", backup.name)], ) def test_create_expire_time_not_set(self): @@ -370,7 +388,8 @@ def test_create_success(self): ) api.create_backup.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", backup.name)], + request=request, + metadata=[("google-cloud-resource-prefix", backup.name)], ) def test_create_w_invalid_encryption_config(self): @@ -585,7 +604,10 @@ def test_update_expire_time_grpc_error(self): with self.assertRaises(Unknown): backup.update_expire_time(expire_time) - backup_update = Backup(name=self.BACKUP_NAME, expire_time=expire_time,) + backup_update = Backup( + name=self.BACKUP_NAME, + expire_time=expire_time, + ) update_mask = {"paths": ["expire_time"]} api.update_backup.assert_called_once_with( backup=backup_update, @@ -607,7 +629,10 @@ def test_update_expire_time_not_found(self): with self.assertRaises(NotFound): backup.update_expire_time(expire_time) - backup_update = Backup(name=self.BACKUP_NAME, expire_time=expire_time,) + backup_update = Backup( + name=self.BACKUP_NAME, + expire_time=expire_time, + ) update_mask = {"paths": ["expire_time"]} api.update_backup.assert_called_once_with( backup=backup_update, @@ -627,7 +652,10 @@ def test_update_expire_time_success(self): backup.update_expire_time(expire_time) - backup_update = Backup(name=self.BACKUP_NAME, expire_time=expire_time,) + backup_update = Backup( + name=self.BACKUP_NAME, + expire_time=expire_time, + ) update_mask = {"paths": ["expire_time"]} api.update_backup.assert_called_once_with( backup=backup_update, diff --git a/tests/unit/test_batch.py b/tests/unit/test_batch.py index d6af07ce7e..2d685acfbf 100644 --- a/tests/unit/test_batch.py +++ b/tests/unit/test_batch.py @@ -20,8 +20,8 @@ TABLE_NAME = "citizens" COLUMNS = ["email", "first_name", "last_name", "age"] VALUES = [ - [u"phred@exammple.com", u"Phred", u"Phlyntstone", 32], - [u"bharney@example.com", u"Bharney", u"Rhubble", 31], + ["phred@exammple.com", "Phred", "Phlyntstone", 32], + ["bharney@example.com", "Bharney", "Rhubble", 31], ] BASE_ATTRIBUTES = { "db.type": "spanner", @@ -293,16 +293,21 @@ def _test_commit_with_request_options(self, request_options=None): ) def test_commit_w_request_tag_success(self): - request_options = RequestOptions(request_tag="tag-1",) + request_options = RequestOptions( + request_tag="tag-1", + ) self._test_commit_with_request_options(request_options=request_options) def test_commit_w_transaction_tag_success(self): - request_options = RequestOptions(transaction_tag="tag-1-1",) + request_options = RequestOptions( + transaction_tag="tag-1-1", + ) self._test_commit_with_request_options(request_options=request_options) def test_commit_w_request_and_transaction_tag_success(self): request_options = RequestOptions( - request_tag="tag-1", transaction_tag="tag-1-1", + request_tag="tag-1", + transaction_tag="tag-1-1", ) self._test_commit_with_request_options(request_options=request_options) @@ -412,7 +417,9 @@ def __init__(self, **kwargs): self.__dict__.update(**kwargs) def commit( - self, request=None, metadata=None, + self, + request=None, + metadata=None, ): from google.api_core.exceptions import Unknown diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py index df5554d153..bd47a2ac31 100644 --- a/tests/unit/test_database.py +++ b/tests/unit/test_database.py @@ -17,7 +17,6 @@ import mock from google.api_core import gapic_v1 - from google.cloud.spanner_v1.param_types import INT64 from google.api_core.retry import Retry @@ -777,7 +776,9 @@ def test_update_ddl_grpc_error(self): database.update_ddl(DDL_STATEMENTS) expected_request = UpdateDatabaseDdlRequest( - database=self.DATABASE_NAME, statements=DDL_STATEMENTS, operation_id="", + database=self.DATABASE_NAME, + statements=DDL_STATEMENTS, + operation_id="", ) api.update_database_ddl.assert_called_once_with( @@ -801,7 +802,9 @@ def test_update_ddl_not_found(self): database.update_ddl(DDL_STATEMENTS) expected_request = UpdateDatabaseDdlRequest( - database=self.DATABASE_NAME, statements=DDL_STATEMENTS, operation_id="", + database=self.DATABASE_NAME, + statements=DDL_STATEMENTS, + operation_id="", ) api.update_database_ddl.assert_called_once_with( @@ -826,7 +829,9 @@ def test_update_ddl(self): self.assertIs(future, op_future) expected_request = UpdateDatabaseDdlRequest( - database=self.DATABASE_NAME, statements=DDL_STATEMENTS, operation_id="", + database=self.DATABASE_NAME, + statements=DDL_STATEMENTS, + operation_id="", ) api.update_database_ddl.assert_called_once_with( @@ -1071,12 +1076,14 @@ def test_execute_partitioned_dml_w_request_options(self): def test_execute_partitioned_dml_w_trx_tag_ignored(self): self._execute_partitioned_dml_helper( - dml=DML_W_PARAM, request_options=RequestOptions(transaction_tag="trx-tag"), + dml=DML_W_PARAM, + request_options=RequestOptions(transaction_tag="trx-tag"), ) def test_execute_partitioned_dml_w_req_tag_used(self): self._execute_partitioned_dml_helper( - dml=DML_W_PARAM, request_options=RequestOptions(request_tag="req-tag"), + dml=DML_W_PARAM, + request_options=RequestOptions(request_tag="req-tag"), ) def test_execute_partitioned_dml_wo_params_retry_aborted(self): @@ -1598,7 +1605,8 @@ def test_context_mgr_success(self): request_options=RequestOptions(transaction_tag=self.TRANSACTION_TAG), ) api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_context_mgr_w_commit_stats_success(self): @@ -1641,7 +1649,8 @@ def test_context_mgr_w_commit_stats_success(self): request_options=RequestOptions(), ) api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) database.logger.info.assert_called_once_with( @@ -1681,7 +1690,8 @@ def test_context_mgr_w_commit_stats_error(self): request_options=RequestOptions(), ) api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) database.logger.info.assert_not_called() @@ -1781,6 +1791,66 @@ class Testing(Exception): self.assertIs(pool._session, session) + def test_context_mgr_session_not_found_error(self): + from google.cloud.exceptions import NotFound + + database = _Database(self.DATABASE_NAME) + session = _Session(database, name="session-1") + session.exists = mock.MagicMock(return_value=False) + pool = database._pool = _Pool() + new_session = _Session(database, name="session-2") + new_session.create = mock.MagicMock(return_value=[]) + pool._new_session = mock.MagicMock(return_value=new_session) + + pool.put(session) + checkout = self._make_one(database) + + self.assertEqual(pool._session, session) + with self.assertRaises(NotFound): + with checkout as _: + raise NotFound("Session not found") + # Assert that session-1 was removed from pool and new session was added. + self.assertEqual(pool._session, new_session) + + def test_context_mgr_table_not_found_error(self): + from google.cloud.exceptions import NotFound + + database = _Database(self.DATABASE_NAME) + session = _Session(database, name="session-1") + session.exists = mock.MagicMock(return_value=True) + pool = database._pool = _Pool() + pool._new_session = mock.MagicMock(return_value=[]) + + pool.put(session) + checkout = self._make_one(database) + + self.assertEqual(pool._session, session) + with self.assertRaises(NotFound): + with checkout as _: + raise NotFound("Table not found") + # Assert that session-1 was not removed from pool. + self.assertEqual(pool._session, session) + pool._new_session.assert_not_called() + + def test_context_mgr_unknown_error(self): + database = _Database(self.DATABASE_NAME) + session = _Session(database) + pool = database._pool = _Pool() + pool._new_session = mock.MagicMock(return_value=[]) + pool.put(session) + checkout = self._make_one(database) + + class Testing(Exception): + pass + + self.assertEqual(pool._session, session) + with self.assertRaises(Testing): + with checkout as _: + raise Testing("Unknown error.") + # Assert that session-1 was not removed from pool. + self.assertEqual(pool._session, session) + pool._new_session.assert_not_called() + class TestBatchSnapshot(_BaseTest): TABLE = "table_name" diff --git a/tests/unit/test_keyset.py b/tests/unit/test_keyset.py index 86a814c752..a7bad4070d 100644 --- a/tests/unit/test_keyset.py +++ b/tests/unit/test_keyset.py @@ -30,19 +30,19 @@ def test_ctor_no_start_no_end(self): self._make_one() def test_ctor_w_start_open_and_start_closed(self): - KEY_1 = [u"key_1"] - KEY_2 = [u"key_2"] + KEY_1 = ["key_1"] + KEY_2 = ["key_2"] with self.assertRaises(ValueError): self._make_one(start_open=KEY_1, start_closed=KEY_2) def test_ctor_w_end_open_and_end_closed(self): - KEY_1 = [u"key_1"] - KEY_2 = [u"key_2"] + KEY_1 = ["key_1"] + KEY_2 = ["key_2"] with self.assertRaises(ValueError): self._make_one(end_open=KEY_1, end_closed=KEY_2) def test_ctor_w_only_start_open(self): - KEY_1 = [u"key_1"] + KEY_1 = ["key_1"] krange = self._make_one(start_open=KEY_1) self.assertEqual(krange.start_open, KEY_1) self.assertEqual(krange.start_closed, None) @@ -50,7 +50,7 @@ def test_ctor_w_only_start_open(self): self.assertEqual(krange.end_closed, []) def test_ctor_w_only_start_closed(self): - KEY_1 = [u"key_1"] + KEY_1 = ["key_1"] krange = self._make_one(start_closed=KEY_1) self.assertEqual(krange.start_open, None) self.assertEqual(krange.start_closed, KEY_1) @@ -58,7 +58,7 @@ def test_ctor_w_only_start_closed(self): self.assertEqual(krange.end_closed, []) def test_ctor_w_only_end_open(self): - KEY_1 = [u"key_1"] + KEY_1 = ["key_1"] krange = self._make_one(end_open=KEY_1) self.assertEqual(krange.start_open, None) self.assertEqual(krange.start_closed, []) @@ -66,7 +66,7 @@ def test_ctor_w_only_end_open(self): self.assertEqual(krange.end_closed, None) def test_ctor_w_only_end_closed(self): - KEY_1 = [u"key_1"] + KEY_1 = ["key_1"] krange = self._make_one(end_closed=KEY_1) self.assertEqual(krange.start_open, None) self.assertEqual(krange.start_closed, []) @@ -74,8 +74,8 @@ def test_ctor_w_only_end_closed(self): self.assertEqual(krange.end_closed, KEY_1) def test_ctor_w_start_open_and_end_closed(self): - KEY_1 = [u"key_1"] - KEY_2 = [u"key_2"] + KEY_1 = ["key_1"] + KEY_2 = ["key_2"] krange = self._make_one(start_open=KEY_1, end_closed=KEY_2) self.assertEqual(krange.start_open, KEY_1) self.assertEqual(krange.start_closed, None) @@ -83,8 +83,8 @@ def test_ctor_w_start_open_and_end_closed(self): self.assertEqual(krange.end_closed, KEY_2) def test_ctor_w_start_closed_and_end_open(self): - KEY_1 = [u"key_1"] - KEY_2 = [u"key_2"] + KEY_1 = ["key_1"] + KEY_2 = ["key_2"] krange = self._make_one(start_closed=KEY_1, end_open=KEY_2) self.assertEqual(krange.start_open, None) self.assertEqual(krange.start_closed, KEY_1) @@ -92,24 +92,24 @@ def test_ctor_w_start_closed_and_end_open(self): self.assertEqual(krange.end_closed, None) def test___eq___self(self): - key_1 = [u"key_1"] + key_1 = ["key_1"] krange = self._make_one(end_open=key_1) self.assertEqual(krange, krange) def test___eq___other_type(self): - key_1 = [u"key_1"] + key_1 = ["key_1"] krange = self._make_one(end_open=key_1) self.assertNotEqual(krange, object()) def test___eq___other_hit(self): - key_1 = [u"key_1"] + key_1 = ["key_1"] krange = self._make_one(end_open=key_1) other = self._make_one(end_open=key_1) self.assertEqual(krange, other) def test___eq___other(self): - key_1 = [u"key_1"] - key_2 = [u"key_2"] + key_1 = ["key_1"] + key_2 = ["key_2"] krange = self._make_one(end_open=key_1) other = self._make_one(start_closed=key_2, end_open=key_1) self.assertNotEqual(krange, other) @@ -117,18 +117,21 @@ def test___eq___other(self): def test_to_pb_w_start_closed_and_end_open(self): from google.cloud.spanner_v1.types.keys import KeyRange as KeyRangePB - key1 = u"key_1" - key2 = u"key_2" + key1 = "key_1" + key2 = "key_2" key_range = self._make_one(start_closed=[key1], end_open=[key2]) key_range_pb = key_range._to_pb() - expected = KeyRangePB(start_closed=[key1], end_open=[key2],) + expected = KeyRangePB( + start_closed=[key1], + end_open=[key2], + ) self.assertEqual(key_range_pb, expected) def test_to_pb_w_start_open_and_end_closed(self): from google.cloud.spanner_v1.types.keys import KeyRange as KeyRangePB - key1 = u"key_1" - key2 = u"key_2" + key1 = "key_1" + key2 = "key_2" key_range = self._make_one(start_open=[key1], end_closed=[key2]) key_range_pb = key_range._to_pb() expected = KeyRangePB(start_open=[key1], end_closed=[key2]) @@ -137,28 +140,28 @@ def test_to_pb_w_start_open_and_end_closed(self): def test_to_pb_w_empty_list(self): from google.cloud.spanner_v1.types.keys import KeyRange as KeyRangePB - key = u"key" + key = "key" key_range = self._make_one(start_closed=[], end_closed=[key]) key_range_pb = key_range._to_pb() expected = KeyRangePB(start_closed=[], end_closed=[key]) self.assertEqual(key_range_pb, expected) def test_to_dict_w_start_closed_and_end_open(self): - key1 = u"key_1" - key2 = u"key_2" + key1 = "key_1" + key2 = "key_2" key_range = self._make_one(start_closed=[key1], end_open=[key2]) expected = {"start_closed": [key1], "end_open": [key2]} self.assertEqual(key_range._to_dict(), expected) def test_to_dict_w_start_open_and_end_closed(self): - key1 = u"key_1" - key2 = u"key_2" + key1 = "key_1" + key2 = "key_2" key_range = self._make_one(start_open=[key1], end_closed=[key2]) expected = {"start_open": [key1], "end_closed": [key2]} self.assertEqual(key_range._to_dict(), expected) def test_to_dict_w_end_closed(self): - key = u"key" + key = "key" key_range = self._make_one(end_closed=[key]) expected = {"end_closed": [key]} self.assertEqual(key_range._to_dict(), expected) @@ -181,7 +184,7 @@ def test_ctor_w_all(self): self.assertEqual(keyset.ranges, []) def test_ctor_w_keys(self): - KEYS = [[u"key1"], [u"key2"]] + KEYS = [["key1"], ["key2"]] keyset = self._make_one(keys=KEYS) @@ -192,8 +195,8 @@ def test_ctor_w_keys(self): def test_ctor_w_ranges(self): from google.cloud.spanner_v1.keyset import KeyRange - range_1 = KeyRange(start_closed=[u"key1"], end_open=[u"key3"]) - range_2 = KeyRange(start_open=[u"key5"], end_closed=[u"key6"]) + range_1 = KeyRange(start_closed=["key1"], end_open=["key3"]) + range_2 = KeyRange(start_open=["key5"], end_closed=["key6"]) keyset = self._make_one(ranges=[range_1, range_2]) @@ -209,8 +212,8 @@ def test_ctor_w_all_and_keys(self): def test_ctor_w_all_and_ranges(self): from google.cloud.spanner_v1.keyset import KeyRange - range_1 = KeyRange(start_closed=[u"key1"], end_open=[u"key3"]) - range_2 = KeyRange(start_open=[u"key5"], end_closed=[u"key6"]) + range_1 = KeyRange(start_closed=["key1"], end_open=["key3"]) + range_2 = KeyRange(start_open=["key5"], end_closed=["key6"]) with self.assertRaises(ValueError): self._make_one(all_=True, ranges=[range_1, range_2]) @@ -229,13 +232,13 @@ def test___eq___w_all_hit(self): self.assertEqual(keyset, other) def test___eq___w_all_miss(self): - keys = [[u"key1"], [u"key2"]] + keys = [["key1"], ["key2"]] keyset = self._make_one(all_=True) other = self._make_one(keys=keys) self.assertNotEqual(keyset, other) def test___eq___w_keys_hit(self): - keys = [[u"key1"], [u"key2"]] + keys = [["key1"], ["key2"]] keyset = self._make_one(keys=keys) other = self._make_one(keys=keys) @@ -243,7 +246,7 @@ def test___eq___w_keys_hit(self): self.assertEqual(keyset, other) def test___eq___w_keys_miss(self): - keys = [[u"key1"], [u"key2"]] + keys = [["key1"], ["key2"]] keyset = self._make_one(keys=keys[:1]) other = self._make_one(keys=keys[1:]) @@ -253,8 +256,8 @@ def test___eq___w_keys_miss(self): def test___eq___w_ranges_hit(self): from google.cloud.spanner_v1.keyset import KeyRange - range_1 = KeyRange(start_closed=[u"key1"], end_open=[u"key3"]) - range_2 = KeyRange(start_open=[u"key5"], end_closed=[u"key6"]) + range_1 = KeyRange(start_closed=["key1"], end_open=["key3"]) + range_2 = KeyRange(start_open=["key5"], end_closed=["key6"]) keyset = self._make_one(ranges=[range_1, range_2]) other = self._make_one(ranges=[range_1, range_2]) @@ -264,8 +267,8 @@ def test___eq___w_ranges_hit(self): def test___eq___w_ranges_miss(self): from google.cloud.spanner_v1.keyset import KeyRange - range_1 = KeyRange(start_closed=[u"key1"], end_open=[u"key3"]) - range_2 = KeyRange(start_open=[u"key5"], end_closed=[u"key6"]) + range_1 = KeyRange(start_closed=["key1"], end_open=["key3"]) + range_2 = KeyRange(start_open=["key5"], end_closed=["key6"]) keyset = self._make_one(ranges=[range_1]) other = self._make_one(ranges=[range_2]) @@ -287,7 +290,7 @@ def test_to_pb_w_all(self): def test_to_pb_w_only_keys(self): from google.cloud.spanner_v1 import KeySetPB - KEYS = [[u"key1"], [u"key2"]] + KEYS = [["key1"], ["key2"]] keyset = self._make_one(keys=KEYS) result = keyset._to_pb() @@ -307,10 +310,10 @@ def test_to_pb_w_only_ranges(self): from google.cloud.spanner_v1 import KeySetPB from google.cloud.spanner_v1.keyset import KeyRange - KEY_1 = u"KEY_1" - KEY_2 = u"KEY_2" - KEY_3 = u"KEY_3" - KEY_4 = u"KEY_4" + KEY_1 = "KEY_1" + KEY_2 = "KEY_2" + KEY_3 = "KEY_3" + KEY_4 = "KEY_4" RANGES = [ KeyRange(start_open=KEY_1, end_closed=KEY_2), KeyRange(start_closed=KEY_3, end_open=KEY_4), @@ -337,7 +340,7 @@ def test_to_dict_w_all(self): self.assertEqual(keyset._to_dict(), expected) def test_to_dict_w_only_keys(self): - KEYS = [[u"key1"], [u"key2"]] + KEYS = [["key1"], ["key2"]] keyset = self._make_one(keys=KEYS) expected = {"keys": KEYS, "ranges": []} @@ -346,10 +349,10 @@ def test_to_dict_w_only_keys(self): def test_to_dict_w_only_ranges(self): from google.cloud.spanner_v1.keyset import KeyRange - key_1 = u"KEY_1" - key_2 = u"KEY_2" - key_3 = u"KEY_3" - key_4 = u"KEY_4" + key_1 = "KEY_1" + key_2 = "KEY_2" + key_3 = "KEY_3" + key_4 = "KEY_4" ranges = [ KeyRange(start_open=[key_1], end_closed=[key_2]), KeyRange(start_closed=[key_3], end_open=[key_4]), @@ -377,7 +380,7 @@ def test_from_dict_w_all(self): def test_from_dict_w_keys(self): klass = self._get_target_class() - keys = [[u"key1"], [u"key2"]] + keys = [["key1"], ["key2"]] mapping = {"keys": keys} keyset = klass._from_dict(mapping) @@ -390,10 +393,10 @@ def test_from_dict_w_ranges(self): from google.cloud.spanner_v1.keyset import KeyRange klass = self._get_target_class() - key_1 = u"KEY_1" - key_2 = u"KEY_2" - key_3 = u"KEY_3" - key_4 = u"KEY_4" + key_1 = "KEY_1" + key_2 = "KEY_2" + key_3 = "KEY_3" + key_4 = "KEY_4" mapping = { "ranges": [ {"start_open": [key_1], "end_closed": [key_2]}, diff --git a/tests/unit/test_session.py b/tests/unit/test_session.py index fe78567f6b..0f297654bb 100644 --- a/tests/unit/test_session.py +++ b/tests/unit/test_session.py @@ -140,7 +140,9 @@ def test_create_ok(self): self.assertEqual(session.session_id, self.SESSION_ID) - request = CreateSessionRequest(database=database.name,) + request = CreateSessionRequest( + database=database.name, + ) gax_api.create_session.assert_called_once_with( request=request, metadata=[("google-cloud-resource-prefix", database.name)] @@ -167,11 +169,13 @@ def test_create_w_labels(self): self.assertEqual(session.session_id, self.SESSION_ID) request = CreateSessionRequest( - database=database.name, session=SessionPB(labels=labels), + database=database.name, + session=SessionPB(labels=labels), ) gax_api.create_session.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) self.assertSpanAttributes( @@ -334,10 +338,14 @@ def test_ping_hit(self): session.ping() - request = ExecuteSqlRequest(session=self.SESSION_NAME, sql="SELECT 1",) + request = ExecuteSqlRequest( + session=self.SESSION_NAME, + sql="SELECT 1", + ) gax_api.execute_sql.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_ping_miss(self): @@ -354,10 +362,14 @@ def test_ping_miss(self): with self.assertRaises(NotFound): session.ping() - request = ExecuteSqlRequest(session=self.SESSION_NAME, sql="SELECT 1",) + request = ExecuteSqlRequest( + session=self.SESSION_NAME, + sql="SELECT 1", + ) gax_api.execute_sql.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_ping_error(self): @@ -374,10 +386,14 @@ def test_ping_error(self): with self.assertRaises(Unknown): session.ping() - request = ExecuteSqlRequest(session=self.SESSION_NAME, sql="SELECT 1",) + request = ExecuteSqlRequest( + session=self.SESSION_NAME, + sql="SELECT 1", + ) gax_api.execute_sql.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_delete_wo_session_id(self): @@ -833,7 +849,8 @@ def unit_of_work(txn, *args, **kw): request_options=RequestOptions(), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_run_in_transaction_w_commit_error(self): @@ -884,7 +901,8 @@ def unit_of_work(txn, *args, **kw): request_options=RequestOptions(), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_run_in_transaction_w_abort_no_retry_metadata(self): @@ -1141,7 +1159,8 @@ def unit_of_work(txn, *args, **kw): request_options=RequestOptions(), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_run_in_transaction_w_abort_w_retry_metadata_deadline(self): @@ -1232,7 +1251,8 @@ def _time(_results=[1, 1.5]): request_options=RequestOptions(), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_run_in_transaction_w_timeout(self): @@ -1388,7 +1408,8 @@ def unit_of_work(txn, *args, **kw): request_options=RequestOptions(), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) database.logger.info.assert_called_once_with( "CommitStats: mutation_count: 4\n", extra={"commit_stats": commit_stats} @@ -1451,7 +1472,8 @@ def unit_of_work(txn, *args, **kw): request_options=RequestOptions(), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) database.logger.info.assert_not_called() @@ -1520,7 +1542,8 @@ def unit_of_work(txn, *args, **kw): request_options=RequestOptions(transaction_tag=transaction_tag), ) gax_api.commit.assert_called_once_with( - request=request, metadata=[("google-cloud-resource-prefix", database.name)], + request=request, + metadata=[("google-cloud-resource-prefix", database.name)], ) def test_delay_helper_w_no_delay(self): diff --git a/tests/unit/test_snapshot.py b/tests/unit/test_snapshot.py index ef162fd29d..5b515f1bbb 100644 --- a/tests/unit/test_snapshot.py +++ b/tests/unit/test_snapshot.py @@ -420,7 +420,7 @@ def _read_helper( from google.cloud.spanner_v1.keyset import KeySet from google.cloud.spanner_v1._helpers import _make_value_pb - VALUES = [[u"bharney", 31], [u"phred", 32]] + VALUES = [["bharney", 31], ["phred", 32]] VALUE_PBS = [[_make_value_pb(item) for item in row] for row in VALUES] struct_type_pb = StructType( fields=[ @@ -541,16 +541,21 @@ def test_read_wo_multi_use(self): self._read_helper(multi_use=False) def test_read_w_request_tag_success(self): - request_options = RequestOptions(request_tag="tag-1",) + request_options = RequestOptions( + request_tag="tag-1", + ) self._read_helper(multi_use=False, request_options=request_options) def test_read_w_transaction_tag_success(self): - request_options = RequestOptions(transaction_tag="tag-1-1",) + request_options = RequestOptions( + transaction_tag="tag-1-1", + ) self._read_helper(multi_use=False, request_options=request_options) def test_read_w_request_and_transaction_tag_success(self): request_options = RequestOptions( - request_tag="tag-1", transaction_tag="tag-1-1", + request_tag="tag-1", + transaction_tag="tag-1-1", ) self._read_helper(multi_use=False, request_options=request_options) @@ -650,7 +655,7 @@ def _execute_sql_helper( _merge_query_options, ) - VALUES = [[u"bharney", u"rhubbyl", 31], [u"phred", u"phlyntstone", 32]] + VALUES = [["bharney", "rhubbyl", 31], ["phred", "phlyntstone", 32]] VALUE_PBS = [[_make_value_pb(item) for item in row] for row in VALUES] MODE = 2 # PROFILE struct_type_pb = StructType( @@ -807,16 +812,21 @@ def test_execute_sql_w_request_options(self): ) def test_execute_sql_w_request_tag_success(self): - request_options = RequestOptions(request_tag="tag-1",) + request_options = RequestOptions( + request_tag="tag-1", + ) self._execute_sql_helper(multi_use=False, request_options=request_options) def test_execute_sql_w_transaction_tag_success(self): - request_options = RequestOptions(transaction_tag="tag-1-1",) + request_options = RequestOptions( + transaction_tag="tag-1-1", + ) self._execute_sql_helper(multi_use=False, request_options=request_options) def test_execute_sql_w_request_and_transaction_tag_success(self): request_options = RequestOptions( - request_tag="tag-1", transaction_tag="tag-1-1", + request_tag="tag-1", + transaction_tag="tag-1-1", ) self._execute_sql_helper(multi_use=False, request_options=request_options) diff --git a/tests/unit/test_streamed.py b/tests/unit/test_streamed.py index de0c8875bf..2714ddfb45 100644 --- a/tests/unit/test_streamed.py +++ b/tests/unit/test_streamed.py @@ -171,11 +171,11 @@ def test__merge_chunk_numeric(self): streamed = self._make_one(iterator) FIELDS = [self._make_scalar_field("total", TypeCode.NUMERIC)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_value(u"1234.") - chunk = self._make_value(u"5678") + streamed._pending_chunk = self._make_value("1234.") + chunk = self._make_value("5678") merged = streamed._merge_chunk(chunk) - self.assertEqual(merged.string_value, u"1234.5678") + self.assertEqual(merged.string_value, "1234.5678") def test__merge_chunk_int64(self): from google.cloud.spanner_v1 import TypeCode @@ -198,11 +198,11 @@ def test__merge_chunk_float64_nan_string(self): streamed = self._make_one(iterator) FIELDS = [self._make_scalar_field("weight", TypeCode.FLOAT64)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_value(u"Na") - chunk = self._make_value(u"N") + streamed._pending_chunk = self._make_value("Na") + chunk = self._make_value("N") merged = streamed._merge_chunk(chunk) - self.assertEqual(merged.string_value, u"NaN") + self.assertEqual(merged.string_value, "NaN") def test__merge_chunk_float64_w_empty(self): from google.cloud.spanner_v1 import TypeCode @@ -238,12 +238,12 @@ def test__merge_chunk_string(self): streamed = self._make_one(iterator) FIELDS = [self._make_scalar_field("name", TypeCode.STRING)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_value(u"phred") - chunk = self._make_value(u"wylma") + streamed._pending_chunk = self._make_value("phred") + chunk = self._make_value("wylma") merged = streamed._merge_chunk(chunk) - self.assertEqual(merged.string_value, u"phredwylma") + self.assertEqual(merged.string_value, "phredwylma") self.assertIsNone(streamed._pending_chunk) def test__merge_chunk_string_w_bytes(self): @@ -254,21 +254,21 @@ def test__merge_chunk_string_w_bytes(self): FIELDS = [self._make_scalar_field("image", TypeCode.BYTES)] streamed._metadata = self._make_result_set_metadata(FIELDS) streamed._pending_chunk = self._make_value( - u"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA" - u"6fptVAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\n" + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA" + "6fptVAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\n" ) chunk = self._make_value( - u"B3RJTUUH4QQGFwsBTL3HMwAAABJpVFh0Q29tbWVudAAAAAAAU0FNUExF" - u"MG3E+AAAAApJREFUCNdj\nYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\n" + "B3RJTUUH4QQGFwsBTL3HMwAAABJpVFh0Q29tbWVudAAAAAAAU0FNUExF" + "MG3E+AAAAApJREFUCNdj\nYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\n" ) merged = streamed._merge_chunk(chunk) self.assertEqual( merged.string_value, - u"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACXBIWXMAAAsTAAAL" - u"EwEAmpwYAAAA\nB3RJTUUH4QQGFwsBTL3HMwAAABJpVFh0Q29tbWVudAAAAAAAU0" - u"FNUExFMG3E+AAAAApJREFUCNdj\nYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\n", + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACXBIWXMAAAsTAAAL" + "EwEAmpwYAAAA\nB3RJTUUH4QQGFwsBTL3HMwAAABJpVFh0Q29tbWVudAAAAAAAU0" + "FNUExFMG3E+AAAAApJREFUCNdj\nYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\n", ) self.assertIsNone(streamed._pending_chunk) @@ -332,12 +332,12 @@ def test__merge_chunk_array_of_string_with_empty(self): streamed = self._make_one(iterator) FIELDS = [self._make_array_field("name", element_type_code=TypeCode.STRING)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_list_value([u"A", u"B", u"C"]) + streamed._pending_chunk = self._make_list_value(["A", "B", "C"]) chunk = self._make_list_value([]) merged = streamed._merge_chunk(chunk) - expected = self._make_list_value([u"A", u"B", u"C"]) + expected = self._make_list_value(["A", "B", "C"]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -348,12 +348,12 @@ def test__merge_chunk_array_of_string(self): streamed = self._make_one(iterator) FIELDS = [self._make_array_field("name", element_type_code=TypeCode.STRING)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_list_value([u"A", u"B", u"C"]) - chunk = self._make_list_value([u"D", u"E"]) + streamed._pending_chunk = self._make_list_value(["A", "B", "C"]) + chunk = self._make_list_value(["D", "E"]) merged = streamed._merge_chunk(chunk) - expected = self._make_list_value([u"A", u"B", u"CD", u"E"]) + expected = self._make_list_value(["A", "B", "CD", "E"]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -364,12 +364,12 @@ def test__merge_chunk_array_of_string_with_null(self): streamed = self._make_one(iterator) FIELDS = [self._make_array_field("name", element_type_code=TypeCode.STRING)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_list_value([u"A", u"B", u"C"]) - chunk = self._make_list_value([None, u"D", u"E"]) + streamed._pending_chunk = self._make_list_value(["A", "B", "C"]) + chunk = self._make_list_value([None, "D", "E"]) merged = streamed._merge_chunk(chunk) - expected = self._make_list_value([u"A", u"B", u"C", None, u"D", u"E"]) + expected = self._make_list_value(["A", "B", "C", None, "D", "E"]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -380,10 +380,10 @@ def test__merge_chunk_array_of_string_with_null_pending(self): streamed = self._make_one(iterator) FIELDS = [self._make_array_field("name", element_type_code=TypeCode.STRING)] streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_list_value([u"A", u"B", u"C", None]) - chunk = self._make_list_value([u"D", u"E"]) + streamed._pending_chunk = self._make_list_value(["A", "B", "C", None]) + chunk = self._make_list_value(["D", "E"]) merged = streamed._merge_chunk(chunk) - expected = self._make_list_value([u"A", u"B", u"C", None, u"D", u"E"]) + expected = self._make_list_value(["A", "B", "C", None, "D", "E"]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -434,14 +434,14 @@ def test__merge_chunk_array_of_array_of_string(self): streamed._metadata = self._make_result_set_metadata(FIELDS) streamed._pending_chunk = self._make_list_value( value_pbs=[ - self._make_list_value([u"A", u"B"]), - self._make_list_value([u"C"]), + self._make_list_value(["A", "B"]), + self._make_list_value(["C"]), ] ) chunk = self._make_list_value( value_pbs=[ - self._make_list_value([u"D"]), - self._make_list_value([u"E", u"F"]), + self._make_list_value(["D"]), + self._make_list_value(["E", "F"]), ] ) @@ -449,9 +449,9 @@ def test__merge_chunk_array_of_array_of_string(self): expected = self._make_list_value( value_pbs=[ - self._make_list_value([u"A", u"B"]), - self._make_list_value([u"CD"]), - self._make_list_value([u"E", u"F"]), + self._make_list_value(["A", "B"]), + self._make_list_value(["CD"]), + self._make_list_value(["E", "F"]), ] ) self.assertEqual(merged, expected) @@ -467,14 +467,14 @@ def test__merge_chunk_array_of_struct(self): ) FIELDS = [self._make_array_field("test", element_type=struct_type)] streamed._metadata = self._make_result_set_metadata(FIELDS) - partial = self._make_list_value([u"Phred "]) + partial = self._make_list_value(["Phred "]) streamed._pending_chunk = self._make_list_value(value_pbs=[partial]) - rest = self._make_list_value([u"Phlyntstone", 31]) + rest = self._make_list_value(["Phlyntstone", 31]) chunk = self._make_list_value(value_pbs=[rest]) merged = streamed._merge_chunk(chunk) - struct = self._make_list_value([u"Phred Phlyntstone", 31]) + struct = self._make_list_value(["Phred Phlyntstone", 31]) expected = self._make_list_value(value_pbs=[struct]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -489,7 +489,7 @@ def test__merge_chunk_array_of_struct_with_empty(self): ) FIELDS = [self._make_array_field("test", element_type=struct_type)] streamed._metadata = self._make_result_set_metadata(FIELDS) - partial = self._make_list_value([u"Phred "]) + partial = self._make_list_value(["Phred "]) streamed._pending_chunk = self._make_list_value(value_pbs=[partial]) rest = self._make_list_value([]) chunk = self._make_list_value(value_pbs=[rest]) @@ -514,14 +514,14 @@ def test__merge_chunk_array_of_struct_unmergeable(self): ) FIELDS = [self._make_array_field("test", element_type=struct_type)] streamed._metadata = self._make_result_set_metadata(FIELDS) - partial = self._make_list_value([u"Phred Phlyntstone", True]) + partial = self._make_list_value(["Phred Phlyntstone", True]) streamed._pending_chunk = self._make_list_value(value_pbs=[partial]) rest = self._make_list_value([True]) chunk = self._make_list_value(value_pbs=[rest]) merged = streamed._merge_chunk(chunk) - struct = self._make_list_value([u"Phred Phlyntstone", True, True]) + struct = self._make_list_value(["Phred Phlyntstone", True, True]) expected = self._make_list_value(value_pbs=[struct]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -534,14 +534,14 @@ def test__merge_chunk_array_of_struct_unmergeable_split(self): ) FIELDS = [self._make_array_field("test", element_type=struct_type)] streamed._metadata = self._make_result_set_metadata(FIELDS) - partial = self._make_list_value([u"Phred Phlyntstone", 1.65]) + partial = self._make_list_value(["Phred Phlyntstone", 1.65]) streamed._pending_chunk = self._make_list_value(value_pbs=[partial]) rest = self._make_list_value(["brown"]) chunk = self._make_list_value(value_pbs=[rest]) merged = streamed._merge_chunk(chunk) - struct = self._make_list_value([u"Phred Phlyntstone", 1.65, "brown"]) + struct = self._make_list_value(["Phred Phlyntstone", 1.65, "brown"]) expected = self._make_list_value(value_pbs=[struct]) self.assertEqual(merged, expected) self.assertIsNone(streamed._pending_chunk) @@ -573,7 +573,7 @@ def test_merge_values_empty_and_partial(self): self._make_scalar_field("married", TypeCode.BOOL), ] streamed._metadata = self._make_result_set_metadata(FIELDS) - BARE = [u"Phred Phlyntstone", 42] + BARE = ["Phred Phlyntstone", 42] VALUES = [self._make_value(bare) for bare in BARE] streamed._current_row = [] streamed._merge_values(VALUES) @@ -591,7 +591,7 @@ def test_merge_values_empty_and_filled(self): self._make_scalar_field("married", TypeCode.BOOL), ] streamed._metadata = self._make_result_set_metadata(FIELDS) - BARE = [u"Phred Phlyntstone", 42, True] + BARE = ["Phred Phlyntstone", 42, True] VALUES = [self._make_value(bare) for bare in BARE] streamed._current_row = [] streamed._merge_values(VALUES) @@ -610,13 +610,13 @@ def test_merge_values_empty_and_filled_plus(self): ] streamed._metadata = self._make_result_set_metadata(FIELDS) BARE = [ - u"Phred Phlyntstone", + "Phred Phlyntstone", 42, True, - u"Bharney Rhubble", + "Bharney Rhubble", 39, True, - u"Wylma Phlyntstone", + "Wylma Phlyntstone", ] VALUES = [self._make_value(bare) for bare in BARE] streamed._current_row = [] @@ -635,7 +635,7 @@ def test_merge_values_partial_and_empty(self): self._make_scalar_field("married", TypeCode.BOOL), ] streamed._metadata = self._make_result_set_metadata(FIELDS) - BEFORE = [u"Phred Phlyntstone"] + BEFORE = ["Phred Phlyntstone"] streamed._current_row[:] = BEFORE streamed._merge_values([]) self.assertEqual(list(streamed), []) @@ -652,7 +652,7 @@ def test_merge_values_partial_and_partial(self): self._make_scalar_field("married", TypeCode.BOOL), ] streamed._metadata = self._make_result_set_metadata(FIELDS) - BEFORE = [u"Phred Phlyntstone"] + BEFORE = ["Phred Phlyntstone"] streamed._current_row[:] = BEFORE MERGED = [42] TO_MERGE = [self._make_value(item) for item in MERGED] @@ -671,7 +671,7 @@ def test_merge_values_partial_and_filled(self): self._make_scalar_field("married", TypeCode.BOOL), ] streamed._metadata = self._make_result_set_metadata(FIELDS) - BEFORE = [u"Phred Phlyntstone"] + BEFORE = ["Phred Phlyntstone"] streamed._current_row[:] = BEFORE MERGED = [42, True] TO_MERGE = [self._make_value(item) for item in MERGED] @@ -690,9 +690,9 @@ def test_merge_values_partial_and_filled_plus(self): self._make_scalar_field("married", TypeCode.BOOL), ] streamed._metadata = self._make_result_set_metadata(FIELDS) - BEFORE = [self._make_value(u"Phred Phlyntstone")] + BEFORE = [self._make_value("Phred Phlyntstone")] streamed._current_row[:] = BEFORE - MERGED = [42, True, u"Bharney Rhubble", 39, True, u"Wylma Phlyntstone"] + MERGED = [42, True, "Bharney Rhubble", 39, True, "Wylma Phlyntstone"] TO_MERGE = [self._make_value(item) for item in MERGED] VALUES = BEFORE + MERGED streamed._merge_values(TO_MERGE) @@ -757,7 +757,7 @@ def test_consume_next_first_set_partial(self): self._make_scalar_field("married", TypeCode.BOOL), ] metadata = self._make_result_set_metadata(FIELDS, transaction_id=TXN_ID) - BARE = [u"Phred Phlyntstone", 42] + BARE = ["Phred Phlyntstone", 42] VALUES = [self._make_value(bare) for bare in BARE] result_set = self._make_partial_result_set(VALUES, metadata=metadata) iterator = _MockCancellableIterator(result_set) @@ -779,7 +779,7 @@ def test_consume_next_first_set_partial_existing_txn_id(self): self._make_scalar_field("married", TypeCode.BOOL), ] metadata = self._make_result_set_metadata(FIELDS, transaction_id=b"") - BARE = [u"Phred Phlyntstone", 42] + BARE = ["Phred Phlyntstone", 42] VALUES = [self._make_value(bare) for bare in BARE] result_set = self._make_partial_result_set(VALUES, metadata=metadata) iterator = _MockCancellableIterator(result_set) @@ -799,7 +799,7 @@ def test_consume_next_w_partial_result(self): self._make_scalar_field("age", TypeCode.INT64), self._make_scalar_field("married", TypeCode.BOOL), ] - VALUES = [self._make_value(u"Phred ")] + VALUES = [self._make_value("Phred ")] result_set = self._make_partial_result_set(VALUES, chunked_value=True) iterator = _MockCancellableIterator(result_set) streamed = self._make_one(iterator) @@ -818,24 +818,24 @@ def test_consume_next_w_pending_chunk(self): self._make_scalar_field("married", TypeCode.BOOL), ] BARE = [ - u"Phlyntstone", + "Phlyntstone", 42, True, - u"Bharney Rhubble", + "Bharney Rhubble", 39, True, - u"Wylma Phlyntstone", + "Wylma Phlyntstone", ] VALUES = [self._make_value(bare) for bare in BARE] result_set = self._make_partial_result_set(VALUES) iterator = _MockCancellableIterator(result_set) streamed = self._make_one(iterator) streamed._metadata = self._make_result_set_metadata(FIELDS) - streamed._pending_chunk = self._make_value(u"Phred ") + streamed._pending_chunk = self._make_value("Phred ") streamed._consume_next() self.assertEqual( list(streamed), - [[u"Phred Phlyntstone", BARE[1], BARE[2]], [BARE[3], BARE[4], BARE[5]]], + [["Phred Phlyntstone", BARE[1], BARE[2]], [BARE[3], BARE[4], BARE[5]]], ) self.assertEqual(streamed._current_row, [BARE[6]]) self.assertIsNone(streamed._pending_chunk) @@ -852,7 +852,7 @@ def test_consume_next_last_set(self): stats = self._make_result_set_stats( rows_returned="1", elapsed_time="1.23 secs", cpu_time="0.98 secs" ) - BARE = [u"Phred Phlyntstone", 42, True] + BARE = ["Phred Phlyntstone", 42, True] VALUES = [self._make_value(bare) for bare in BARE] result_set = self._make_partial_result_set(VALUES, stats=stats) iterator = _MockCancellableIterator(result_set) @@ -879,7 +879,7 @@ def test___iter___one_result_set_partial(self): self._make_scalar_field("married", TypeCode.BOOL), ] metadata = self._make_result_set_metadata(FIELDS) - BARE = [u"Phred Phlyntstone", 42] + BARE = ["Phred Phlyntstone", 42] VALUES = [self._make_value(bare) for bare in BARE] for val in VALUES: self.assertIsInstance(val, Value) @@ -902,13 +902,13 @@ def test___iter___multiple_result_sets_filled(self): ] metadata = self._make_result_set_metadata(FIELDS) BARE = [ - u"Phred Phlyntstone", + "Phred Phlyntstone", 42, True, - u"Bharney Rhubble", + "Bharney Rhubble", 39, True, - u"Wylma Phlyntstone", + "Wylma Phlyntstone", 41, True, ] @@ -939,15 +939,15 @@ def test___iter___w_existing_rows_read(self): self._make_scalar_field("married", TypeCode.BOOL), ] metadata = self._make_result_set_metadata(FIELDS) - ALREADY = [[u"Pebbylz Phlyntstone", 4, False], [u"Dino Rhubble", 4, False]] + ALREADY = [["Pebbylz Phlyntstone", 4, False], ["Dino Rhubble", 4, False]] BARE = [ - u"Phred Phlyntstone", + "Phred Phlyntstone", 42, True, - u"Bharney Rhubble", + "Bharney Rhubble", 39, True, - u"Wylma Phlyntstone", + "Wylma Phlyntstone", 41, True, ] @@ -1113,11 +1113,11 @@ def _normalize_int_array(cell): def _normalize_float(cell): - if cell == u"Infinity": + if cell == "Infinity": return float("inf") - if cell == u"-Infinity": + if cell == "-Infinity": return float("-inf") - if cell == u"NaN": + if cell == "NaN": return float("nan") if cell is not None: return float(cell) diff --git a/tests/unit/test_transaction.py b/tests/unit/test_transaction.py index d11a3495fe..d4d9c99c02 100644 --- a/tests/unit/test_transaction.py +++ b/tests/unit/test_transaction.py @@ -388,16 +388,21 @@ def test_commit_w_return_commit_stats(self): self._commit_helper(return_commit_stats=True) def test_commit_w_request_tag_success(self): - request_options = RequestOptions(request_tag="tag-1",) + request_options = RequestOptions( + request_tag="tag-1", + ) self._commit_helper(request_options=request_options) def test_commit_w_transaction_tag_ignored_success(self): - request_options = RequestOptions(transaction_tag="tag-1-1",) + request_options = RequestOptions( + transaction_tag="tag-1-1", + ) self._commit_helper(request_options=request_options) def test_commit_w_request_and_transaction_tag_success(self): request_options = RequestOptions( - request_tag="tag-1", transaction_tag="tag-1-1", + request_tag="tag-1", + transaction_tag="tag-1-1", ) self._commit_helper(request_options=request_options) @@ -545,16 +550,21 @@ def test_execute_update_new_transaction(self): self._execute_update_helper() def test_execute_update_w_request_tag_success(self): - request_options = RequestOptions(request_tag="tag-1",) + request_options = RequestOptions( + request_tag="tag-1", + ) self._execute_update_helper(request_options=request_options) def test_execute_update_w_transaction_tag_success(self): - request_options = RequestOptions(transaction_tag="tag-1-1",) + request_options = RequestOptions( + transaction_tag="tag-1-1", + ) self._execute_update_helper(request_options=request_options) def test_execute_update_w_request_and_transaction_tag_success(self): request_options = RequestOptions( - request_tag="tag-1", transaction_tag="tag-1-1", + request_tag="tag-1", + transaction_tag="tag-1-1", ) self._execute_update_helper(request_options=request_options) @@ -717,16 +727,21 @@ def test_batch_update_wo_errors(self): ) def test_batch_update_w_request_tag_success(self): - request_options = RequestOptions(request_tag="tag-1",) + request_options = RequestOptions( + request_tag="tag-1", + ) self._batch_update_helper(request_options=request_options) def test_batch_update_w_transaction_tag_success(self): - request_options = RequestOptions(transaction_tag="tag-1-1",) + request_options = RequestOptions( + transaction_tag="tag-1-1", + ) self._batch_update_helper(request_options=request_options) def test_batch_update_w_request_and_transaction_tag_success(self): request_options = RequestOptions( - request_tag="tag-1", transaction_tag="tag-1-1", + request_tag="tag-1", + transaction_tag="tag-1-1", ) self._batch_update_helper(request_options=request_options) @@ -874,7 +889,9 @@ def rollback(self, session=None, transaction_id=None, metadata=None): return self._rollback_response def commit( - self, request=None, metadata=None, + self, + request=None, + metadata=None, ): assert not request.single_use_transaction self._committed = (